我建立与tastypie一个API,基于用户数据的Django应用程序。 资源是这样的:
class PizzaResource(ModelResource):
toppings = fields.ToManyField(
'project.app.api.ToppingResource',
'topping_set'
)
class Meta:
authentication = SessionAuthentication()
queryset = Pizza.objects.all()
def apply_authorization_limits(self, request, object_list):
return object_list.filter(users=request.user)
class ToppingResource(ModelResource):
pizza = fields.ForeignKey(PizzaResource, 'pizza')
class Meta:
authentication = SessionAuthentication()
queryset = Topping.objects.filter()
根据该模型是这样的:
class Pizza(model):
users = ManyToManyField(User)
toppings = ManyToManyField(Topping)
# other stuff
class Topping(Model):
used_by = ManyToManyField(User)
# other stuff
现在我想做的是过滤toppings
与上市pizza
由Topping.used_by
场。 我刚刚找到了如何通过请求不相关的数据这一领域过滤 。
如何过滤的关系字段tastypie
通过请求数据?