I had a problem with Tastypie not saving changes to my object when I do a PUT that causes the foreignkey field to be null.
Here is my ModelResource:
class FolderResource(ModelResource): parent = fields.ForeignKey('self','parent',full=True,default=None,blank=True,null=True) project = fields.ForeignKey(ProjectResource,'project',full=False) class Meta: queryset = Folder.objects.all() authentication = Authentication() authorization = Authorization() resource_name = 'folder' include_absolute_url = True always_return_data = True filtering = { "slug": ('exact', 'startswith',), "name": ALL, "project":ALL_WITH_RELATIONS, "parent":ALL_WITH_RELATIONS, "id":('exact') }
I have an existing folder object with the following data:
{ absolute_url: "/projects/1/files/5/", created_date: "13 Feb 2012", id: "5", modified_date: "15 Feb 2012", modified_file: null, name: "testfolder2", parent: { absolute_url: "/projects/1/files/1/", created_date: "4 Feb 2012", id: "1", modified_date: "15 Feb 2012", modified_file: null, name: "testfolder1", parent: null, project: "/projects/api/v1/project/1/", removed_date: null, resource_uri: "/projects/api/v1/folder/1/", slug: "testfolder1" }, project: "/projects/api/v1/project/1/", removed_date: null, resource_uri: "/projects/api/v1/folder/5/", slug: "testfolder2" }
I will try to output the following data to '/ projects / api / v1 / folder / 5 /':
{ parent: null }
I get no errors, everything seems fine, but nothing is stored in the database. Can someone tell me what I am doing wrong or why the change is not saved?