Is it possible to use TastyPie to update a ForeignKey
field to None
?
Related question: tastypie won't remove foreignkey reference during PUT
What I have:
class SomeObject(models.Model):
some_field = models.ForeignKey(SomeOtherObject, null=True)
(and of course the corresponding TastyPie resource class that works fine for updating other fields)
What I want:
To update some_field
to None
using TastyPie.
What I've tried (in JavaScript):
$.put('/my/api/model/someobject/42/', { some_field: null });
$.put('/my/api/model/someobject/42/', { some_field: '/my/api/model/someotherobject/null/' });
$.put('/my/api/model/someobject/42/', { some_field: '' });
$.put('/my/api/model/someobject/42/', { some_field: 0 });
$.put('/my/api/model/someobject/42/', { some_field: false });
And so on. These all result in 404 or 400. Some result in 204, but the database is not updated.
Reading through the code in full_dehydrate()
, it seems it might not be possible at present do so.
I've looked at the recent code on github, and I'm not convinced this is possible.
obj_update()
method on my resource class, wherein I checkif 'some_field' in bundle.data and bundle.data['some_field'] is None:
, at which point I set the object'ssome_field
toNone
andsave()
it. In my JavaScript, I pass{ some_field: null }
– Saccharometer