我的Django模型是這樣的:如何使用django-tastypie爲繼承另一個模型的模型創建ModelResource?
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
屬性。好。因此,我爲Session
和Invoice
創建了ModelResource
,想象Tastypie可以透過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
模型是一個抽象類。
請添加你的url conf(s) – 2012-07-18 14:23:45