私のジャンゴモデルは次のようになります:
class Session(models.Model):
...
class Document(models.Model):
session = models.ForeignKey(Session)
date_created = models.DateTimeField(auto_now_add=True)
class Meta:
abstract = True
class Invoice(Document):
number = models.PositiveIntegerField()
# and some other fields
class SupplyRequest(Document):
# fields here
このように、すべてInvoice
のSupplyRequest
インスタンスは にリンクされSession
、属性を持ちdate_created
ます。わかった。そこで、Tastypie がモデル フィールドを透過的に通過できることを想像して、 ModelResource
forSession
と forを作成しました。しかし、動作しません:Invoice
Document
class SessionResource(ModelResource):
class Meta:
queryset = Session.objects.all()
...
class InvoiceResource(ModelResource):
session = fields.ForeignKey(SessionResource, 'session')
class Meta:
queryset = Invoice.objects.all()
...
請求書をシリアル化しようとすると、次のエラー メッセージが表示されました。
NoReverseMatch: Reverse for 'api_dispatch_detail' with arguments '()' and keyword arguments '{'pk': 1, 'resource_name': 'session'}' not found.
Tastypie を使用してモデルの継承を処理する方法はありますか?
Document
モデルが抽象クラスであることを忘れていました。