私は私のapiが私にtastypieと逆の関係データを与えるようにしようとしています。Tastypie Reverse Relation
私は2つのモデル、DocumentContainerを持っている、とのDocumentEventが、彼らは次のように関連しています
DocumentContainerが多くDocumentEvents
を持ってここに私のコードです:
class DocumentContainerResource(ModelResource):
pod_events = fields.ToManyField('portal.api.resources.DocumentEventResource', 'pod_events')
class Meta:
queryset = DocumentContainer.objects.all()
resource_name = 'pod'
authorization = Authorization()
allowed_methods = ['get']
def dehydrate_doc(self, bundle):
return bundle.data['doc'] or ''
class DocumentEventResource(ModelResource):
pod = fields.ForeignKey(DocumentContainerResource, 'pod')
class Meta:
queryset = DocumentEvent.objects.all()
resource_name = 'pod_event'
allowed_methods = ['get']
私は私のAPIのURLを打つとき、私は次のエラーが表示されます。
DocumentContainer' object has no attribute 'pod_events
誰でも手助けできますか?
ありがとうございました。
ええと、変更の後でさえ、それは私にとっては役に立たなかった。今度は "'DocumentContainer'オブジェクトに属性 'pod_event_set'がありません" – rookieRailer
@rookieRailerあなたのmodels.pyから関連するスニペットを投稿してもよろしいですか? –
ForeignKeyはToOneFieldのエイリアスです。 –