My django models looks like:
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
That way, every Invoice and SupplyRequest instances are linked to a Session and have a date_created attribute. OK. So, I created a ModelResource for Session and for Invoice, imagining that Tastypie can walk through Document model fields transparently. But does not work:
class SessionResource(ModelResource):
class Meta:
queryset = Session.objects.all()
...
class InvoiceResource(ModelResource):
session = fields.ForeignKey(SessionResource, 'session')
class Meta:
queryset = Invoice.objects.all()
...
When I try to serialize an Invoice I got the following error message:
NoReverseMatch: Reverse for 'api_dispatch_detail' with arguments '()' and keyword arguments '{'pk': 1, 'resource_name': 'session'}' not found.
Is there any way to deal with model inheritance using Tastypie?
I’ve forgotten to mention that Document model is an abstract class.
I think you must have forgotten to set the url SessionResource.
You do this in urls.py?
Hugs.