I have Page model with GFK.
class Page(models.Model):
title = models.CharField(max_length=200)
content_type = models.ForeignKey(ContentType,null=True,blank=True)
object_id = models.CharField(max_length=255,null=True,blank=True)
content_object = generic.GenericForeignKey('content_type', 'object_id')
and
class TextContent(models.Model):
content = models.TextField(null=True, blank=True)
pages = generic.GenericRelation(Page)
I do Page.objects.get(pk=1).content_object and I got it.
Help me please to show a link (or output to JSON) that anchored object in REST.
class PageResource(ModelResource):
content_object = fields.?????
class Meta:
queryset = Page.objects.all()
resource_name = 'page'
How to do it right?
Thanks!
Vitaliy
There’s currently no easy way using generic relations in tastypie. There have been some patches submitted at tastypie github page but these have not been merged as of this writing.
The easiest way to do this, define a contenttype resource and use that for the resources having a generic relation. Something along the lines of:
Hope this helps.