gpt4 book ai didi

python - 在 tastypie 中发布 url

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:17 24 4
gpt4 key购买 nike

我是 django 中的 tastypie 新手。我有一个组织模型。在 api.py 中

class OrganisationResource(ModelResource):
create_user = fields.ForeignKey(PersonResource, 'create_user', null=True, full=True)
update_user = fields.ForeignKey(PersonResource, 'update_user', null=True, full=True)
location = fields.ForeignKey(LocationResource, 'location', null=True, full=True)
class Meta:
allowed_methods = ['post','get','delete','patch','put']
queryset = Organization.objects.all()
resource_name = 'organisation'
authorization = Authorization()
authentication = Authentication()
always_return_data = True

API 网址是,

http://127.0.0.1:8000/api/v1/organisation/

对上述链接的发布请求正在将该数据保存到数据库中。但我怀疑我是否可以使用单独的链接来发布或覆盖当前网址,以便我可以将发布请求发送到该链接。喜欢

http://127.0.0.1:8000/api/v1/organisation/create

最佳答案

您可以使用 prependurls 为帖子创建单独的 url,有用 link

class OrganisationCreateResource(ModelResource):
create_user = fields.ForeignKey(PersonResource, 'create_user', null=True, full=True)
update_user = fields.ForeignKey(PersonResource, 'update_user', null=True, full=True)
location = fields.ForeignKey(LocationResource, 'location', null=True, full=True)
class Meta:
allowed_methods = ['post']
queryset = Organization.objects.all()
detail_uri_name = 'create'
resource_name = 'organisation'
authorization = Authorization()
authentication = Authentication()
always_return_data = True
def prepend_urls(self):
return [
url(r'^(?P<resource_name>%s)/create/' % self._meta.resource_name, self.wrap_view('dispatch_detail'), name='api_dispatch_detail'),
]

关于python - 在 tastypie 中发布 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112849/

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