Python 如何为使用django tastypie继承另一个模型的模型创建ModelResource?
我的django型号看起来像:Python 如何为使用django tastypie继承另一个模型的模型创建ModelResource?,python,django,tastypie,Python,Django,Tastypie,我的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):
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
这样,每个发票
和供应商请求
实例都链接到一个会话
,并具有一个创建日期
属性。好啊因此,我为会话
和发票
创建了一个模型资源
,设想Tastypie可以透明地遍历文档
模型字段。但不起作用:
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.
有没有办法使用tastype处理模型继承
我忘了提到
文档
模型是一个抽象类。我想您一定忘了设置url SessionResource
from tastypie.api import Api
api = Api()
api.register(SessionResource())
urlpatterns += patterns('',
(r'^api/', include(api.urls)),
)
你是在url.py中这样做的吗
拥抱。上帝!被疲劳出卖了。。。你完全正确!非常感谢。