在PUT期间,tastypie不会删除foreignkey引用

时间:2012-02-16 08:08:51

标签: python django tastypie

当我执行PUT导致将foreignkey字段设置为null时,我遇到Tastypie没有保存对象更改的问题。

这是我的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"
}

我会尝试将以下数据输入'/ projects / api / v1 / folder / 5 /':

{
    parent: null
}

我没有收到任何错误,一切似乎都没问题,但没有任何东西被保存到数据库中。任何人都可以告诉我我做错了什么或者为什么没有保存更改?

1 个答案:

答案 0 :(得分:0)

如果要进行部分更新,则需要PATCH方法。