我是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 url是,
http://127.0.0.1:8000/api/v1/organisation/
对上述链接的发布请求将该数据保存到数据库。但我怀疑是否可以使用单独的链接发布或覆盖当前网址,以便我可以将发布请求发送到该链接。像
http://127.0.0.1:8000/api/v1/organisation/create
答案 0 :(得分:1)
您可以使用prependurls
有用的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'),
]