当我执行PUT时,tastype不保存对我的对象的更改,这会导致foreignkey字段设置为空。
这是我的模型资源:

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
}

我没有返回任何错误,一切看起来都很好,但没有保存到数据库。有人能告诉我我做错了什么吗?或者为什么零钱没有存起来?

最佳答案

如果要进行部分更新,则需要使用修补程序方法。

09-17 00:14