|
|
|
|
@ -13,6 +13,7 @@ class ContentCreateSerializer(serializers.Serializer): |
|
|
|
|
'text', |
|
|
|
|
'image', |
|
|
|
|
'image-text', |
|
|
|
|
'images', |
|
|
|
|
'video', |
|
|
|
|
) |
|
|
|
|
type = serializers.ChoiceField(choices=TYPE_CHOICES) |
|
|
|
|
@ -27,6 +28,8 @@ class ContentCreateSerializer(serializers.Serializer): |
|
|
|
|
return ImageTextSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Video): |
|
|
|
|
return VideoSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Gallery): |
|
|
|
|
return GallerySerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
return super(ContentSerializer, self).to_representation(obj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -154,32 +157,6 @@ class VideoSerializer(VideoCreateSerializer): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContentSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = Content |
|
|
|
|
fields = ( |
|
|
|
|
'id', |
|
|
|
|
'course', |
|
|
|
|
'lesson', |
|
|
|
|
'title', |
|
|
|
|
'position', |
|
|
|
|
'created_at', |
|
|
|
|
'update_at', |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def to_representation(self, obj): |
|
|
|
|
if isinstance(obj, Image): |
|
|
|
|
return ImageSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Text): |
|
|
|
|
return TextSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, ImageText): |
|
|
|
|
return ImageTextSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Video): |
|
|
|
|
return VideoSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
return super(ContentSerializer, self).to_representation(obj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GalleryImageCreateSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
@ -210,7 +187,10 @@ class GallerySerializer(serializers.ModelSerializer): |
|
|
|
|
model = Gallery |
|
|
|
|
fields = ( |
|
|
|
|
'id', |
|
|
|
|
'course', |
|
|
|
|
'lesson', |
|
|
|
|
'title', |
|
|
|
|
'position', |
|
|
|
|
'gallery_images', |
|
|
|
|
'created_at', |
|
|
|
|
'update_at', |
|
|
|
|
@ -221,3 +201,31 @@ class GallerySerializer(serializers.ModelSerializer): |
|
|
|
|
'created_at', |
|
|
|
|
'update_at', |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContentSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
model = Content |
|
|
|
|
fields = ( |
|
|
|
|
'id', |
|
|
|
|
'course', |
|
|
|
|
'lesson', |
|
|
|
|
'title', |
|
|
|
|
'position', |
|
|
|
|
'created_at', |
|
|
|
|
'update_at', |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def to_representation(self, obj): |
|
|
|
|
if isinstance(obj, Image): |
|
|
|
|
return ImageSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Text): |
|
|
|
|
return TextSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, ImageText): |
|
|
|
|
return ImageTextSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Video): |
|
|
|
|
return VideoSerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
elif isinstance(obj, Gallery): |
|
|
|
|
return GallerySerializer(obj, context=self.context).to_representation(obj) |
|
|
|
|
return super(ContentSerializer, self).to_representation(obj) |
|
|
|
|
|