3
我遇到問題Tastypie不會將更改保存到我的對象,當我執行導致外鍵字段設置爲空的PUT時。tastypie在PUT期間不會刪除外鍵引用
這裏是我的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')
}
我有以下數據的現有文件夾對象:
{
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"
}
我會嘗試以下數據放到「/項目/ API/V1 /文件夾/ 5 /':
{
parent: null
}
我不回覆任何錯誤,一切都很好,但沒有任何東西被保存到數據庫。任何人都可以告訴我我做錯了什麼,或者爲什麼沒有保存更改?
運氣好嗎?我有同樣的問題。 – djsmith 2012-03-14 01:36:11
同樣在這裏...使用NamespacedModelResource btw。使用PATCH時無法使其工作。 parent:null在這個例子中只是空的父級:( – gabn88 2014-10-08 17:56:14