My view .
class EventRVSPResource(ModelResource):
event = fields.ForeignKey(EventResource, 'event')
created_by = fields.ForeignKey(UserResource, 'created_by')
class Meta:
queryset = EventRsvp.objects.all()
authorization = Authorization()
resource_name = 'eventrvsp'
filtering = {
'event':ALL_WITH_RELATIONS,
'created_by': ALL,
}
but sending data using curl it is working fine. it showing 201
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"created_by": "/mobapp/api/v1/user/1/","event": "/mobapp/api/v1/eventlist/5/","notes": "Going","past_status": "DG","status": "Y"}' http://192.168.1.8:9000/mobapp/api/v1/eventrvsp/
My Http request to django-tastypie.But still it is showing error.I dont whats wrong with it
var url = "http://192.168.1.8:9000/mobapp/api/v1/eventrvsp/";
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug();
alert(e.error);
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
client.open("POST", url);
// Send the request.
client.send({"created_by": "/mobapp/api/v1/user/1/","event": "/mobapp/api/v1/eventlist/4/","notes": "Going","past_status": "DG","status": "Y"});
The problem is you need to set header "content-type" to "application/json" and use JSON.stringify
you can find ref here:http://django-tastypie.readthedocs.org/en/latest/interacting.html#creating-a-new-resource-post
Note: always place setRequestHeader
after open
befor send
var data = JSON.stringify({created_by:"/mobapp/api/v1/user/1/",event:"/mobapp/api/v1/eventlist/5/",notes:"Going",past_status:"DG",status:"Y"});
.
.
.
.
.
client.open("POST", url);
client.setRequestHeader("Content-Type", "application/json");
client.send(data);