Problem saving a model related to another model
bitliner opened this issue · 3 comments
I have a Product model and a Store model. Product has a hasOne relation that refers to Store
I create a Product instance, that has got 'store' attribute that has got resource_uri attribute.
But when i try to save the Product instance, i get the error:
venv/lib/python2.6/site-packages/django/db/models/fields/init.py", line 537, in get_prep_value\n return int(value)\n\nTypeError: int() argument must be a string or a number, not 'RelatedManager'\n"}
(i think that Django exptecs store_id as int, but it finds a RelatedManager )
The code of my simple app is here: https://bitbucket.org/bitliner/mdd-with-backbone-and-django
It has a index.html that display a simple Product instance, and it has a Save button that save to the db.
The backbone code is in webinf/templates/index.html, the tastypie and models are in src/DjangoBackboneRelational folder
I have found my problem, it isn't from backbone-tastypie but it is caused by a bad setting of backbone model
I cannot setting in a right way the backbone relational model.
For example (remembering that Product model has a hasOne relation to Store):
product.set({store: '/api/v1/store/1/' });
leaves product.store undefined.
I can set product.store attributes only like this:
product.set({store: {resource_uri: '/api/v1/store/1/'} });
but this throws exception : return int(value)\n\nTypeError: int() argument must be a string or a number, not 'RelatedManager'
Eh, it doesn't sound like this is an issue with Backbone-tastypie, or even Backbone-relational; rather, something's wrong in the Django app? Please post a jsfiddle if you want help on the javascript part.