我正在尝试使用 django sweetpie,但遇到了一些麻烦。这是我的 api.py:
from tastypie.resources import ModelResource
from tastypie import fields
from app.models import First, Second, Third
class FirstResource(ModelResource):
second = fields.ToManyField('app.api.SecondResource', 'second_set', related_name='first', null=True, blank=True, full=True)
class Meta:
queryset = First.objects.all()
resource_name = 'first'
class SecondResource(ModeResource):
first = fields.ForeignKey(FirstResource, 'first', full=True)
third = fields.ToManyField('app.api.ThirdResource', 'third_set', related_name='second', null=True, blank=True, full=True)
class Meta:
queryset = Second.objects.all()
resource_name = 'second'
class ThirdResource(ModelResource):
poll = fields.ForeignKey(SecondResource, 'second', full=True)
class Meta:
queryset = Third.objects.all()
resource_name = 'third'
当我尝试使用它获取 SecondResource 时,http://127.0.0.1:8000/app/api/v1/second/
它包括 FirstResource,但我也希望与 ThirdResource 相关联。现在它只给了我一个空数组。我怎样才能做到这一点?