我的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