我想知道是否有人有一个将Django REST框架与django-polymorphic相结合的Pythonic解决方案.
鉴于:
class GalleryItem(PolymorphicModel):
gallery_item_field = models.CharField()
class Photo(GalleryItem):
custom_photo_field = models.CharField()
class Video(GalleryItem):
custom_image_field = models.CharField()
Run Code Online (Sandbox Code Playgroud)
如果我想要一个django-rest-framework中所有GalleryItem的列表,它只会给我GalleryItem(父模型)的字段,因此:id,gallery_item_field和polymorphic_ctype.那不是我想要的.我想要custom_photo_field,如果它是一个Photo实例,我想要custom_image_field,如果它是一个视频.