是否可以使用tastypie在相關模型中包含字段?Tastypie訪問來自繼承模型的字段
按我下面的模型:如果我堅持一個VideoContent和一個實例的TextContent到數據庫,然後我就可以從我的內容資源2點的對象,但是,沒有附加字段都可用。
是否可以包含來自相關模型的字段(在本例中爲視頻url和文本內容),並且可以滿足未來添加更多內容類型的需求,而無需重寫Content Resource,或者我來從這個錯誤的方向?
我們的目標是能夠在不必修改的內容資源更CONTENTTYPES擴展(假設有可能把它擺在首位的工作)
Models.py:
class Content(models.Model):
parent = models.ForeignKey('Content', related_name='children', null=True, blank=True)
class TextContent(Content):
text = models.CharField(max_length=100)
class VideoContent(Content):
url = models.CharField(max_length=1000)
然後我的資源:
class ContentResource(ModelResource):
children = fields.ToManyField('myapp.api.resources.ContentResource', 'children', null=True, full=True)
class Meta:
resource_name = 'content'
queryset = ContentResource.objects.all()
authorization = Authorization()
always_return_data = True