0

私のジャンゴモデルは次のようになります:

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

このように、すべてInvoiceSupplyRequestインスタンスは にリンクされSession、属性を持ちdate_createdます。わかった。そこで、Tastypie がモデル フィールドを透過的に通過できることを想像して、 ModelResourceforSessionと forを作成しました。しかし、動作しません:InvoiceDocument

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モデルが抽象クラスであることを忘れていました。

4

1 に答える 1

2

URL SessionResource を設定するのを忘れたに違いないと思います。

from tastypie.api import Api

api = Api()

api.register(SessionResource())

urlpatterns += patterns('',
    (r'^api/', include(api.urls)),
)

あなたはurls.pyでこれを行いますか?

抱擁。

于 2012-07-19T18:24:41.863 に答える