gpt4 book ai didi

python - tastypie 不会在 PUT 期间删除外键引用

转载 作者:行者123 更新时间:2023-11-28 19:26:41 26 4
gpt4 key购买 nike

当我执行导致外键字段设置为空的 PUT 时,Tastypie 没有保存对我的对象的更改。

这是我的模型资源:

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
}

我没有返回任何错误,一切似乎都很好,但没有任何内容保存到数据库中。谁能告诉我我做错了什么或者为什么没有保存更改?

最佳答案

如果你想进行部分更新,那么你需要一个 PATCH 方法。

关于python - tastypie 不会在 PUT 期间删除外键引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9307619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com