I have the following problem with Django 1.7 and django-tastypie 0.13.3, upgrading from Django 1.6 and django-tastypie 0.9.14.
urls.py
from relationships.api import RelationResource
v1_api = Api(api_name='v1')
v1_api.register(RelationResource())
In the template this code is called:
var Relationships = Relationships || {};
$.ajaxPrefilter(function(options, originalOptions, jqXHR){
if(options["type"].toLowerCase() != "get") {
options["contentType"] = "application/json";
options["data"] = JSON.stringify(originalOptions["data"]);
}
});
Relationships.Relation = can.Model({
attributes: {
id: 'to_int'
},
convert: {
to_int: function(raw) {
return parseInt(raw);
}
},
models: function(data){
return data.objects;
},
model: function( attributes ) {
return new this(attributes);
},
findAll: "GET /api/v1/relationships/",
findOne: "GET /api/v1/relationships/{id}/",
create: "POST /api/v1/relationships/",
update: "PUT /api/v1/relationships/{id}/",
destroy: "DELETE /api/v1/relationships/{id}/"
},{
});
Relationships.Button = can.Control({
init: function(element, options){
},
'click': function(el, ev){
var following = Boolean(el.data('following'));
var from_user = el.data('from_user');
var to_user = el.data('to_user');
var url = '/api/v1/relationships/';
var from_user_uri = '/api/v1/users/' + from_user + '/';
var to_user_uri = '/api/v1/users/' + to_user + '/';
var self = this;
if(following) {
Relationships.Relation.findAll({
'from_user': from_user, 'to_user': to_user}, function(items){
if(items.length == 1) {
var item = new Relationships.Relation(items[0]);
item.destroy(function(){
});
}
});
} else {
var item = new Relationships.Relation({'to_user': to_user_uri});
item.save(function(){
});
}
}
});
This gives an error: POST http://0.0.0.0:8000/api/v1/relationships/ 400 (BAD REQUEST)
Firebug output Post tab
to_user "/api/v1/users/6/"
Response tab
{"relationships": {"to_user": ["Select a valid choice. That choice is not one of the available choices ."]}}
This code worked fine with the previous versions of django and tastypie. Any idea what I am missing?