【发布时间】:2012-07-18 14:12:41
【问题描述】:
我的 django 模型看起来像:
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 模型是一个抽象类。
【问题讨论】: