0
我想用django tastypie但有一些麻煩。這裏是我的api.py:Django Tastypie - 包括很多領域
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'
當我試着使用http://127.0.0.1:8000/app/api/v1/second/
它包括FirstResource得到SecondResource,但我也希望相關的ThirdResource。 現在它只給我一個空的數組。我怎樣才能做到這一點?
很抱歉,在第三類名稱的拼寫錯誤。 – romainberger 2013-02-24 00:22:38