From abf0bc20629e26b3835f8916a4ac28abedd540fa Mon Sep 17 00:00:00 2001 From: Hina Khadim Date: Tue, 24 Oct 2023 15:54:36 +0500 Subject: [PATCH] fix: add banner image in programs --- course_discovery/apps/api/serializers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/course_discovery/apps/api/serializers.py b/course_discovery/apps/api/serializers.py index bf0f651fe3..782753798b 100644 --- a/course_discovery/apps/api/serializers.py +++ b/course_discovery/apps/api/serializers.py @@ -1914,7 +1914,7 @@ class MinimalProgramSerializer(TaggitSerializer, FlexFieldsSerializerMixin, Base """ authoring_organizations = MinimalOrganizationSerializer(many=True) - banner_image = StdImageSerializerField(allow_null=True, required=False) + banner_image = serializers.SerializerMethodField() courses = serializers.SerializerMethodField() type = serializers.SlugRelatedField(slug_field='slug', queryset=ProgramType.objects.all()) type_attrs = ProgramTypeAttrsSerializer(source='type', required=False) @@ -2056,6 +2056,16 @@ def get_card_image_url(self, obj): if obj.card_image: return obj.card_image.url return obj.card_image_url + + def get_banner_image(self, obj): + if not obj.card_image_url: + return None + return { + 'large': {'url' : obj.card_image_url, "width": 1440, "height": 480}, + 'medium': {'url' : obj.card_image_url, "width": 726, "height": 242}, + 'small': {'url' : obj.card_image_url, "width": 435, "height": 145}, + 'x-small': {'url' : obj.card_image_url, "width": 348, "height": 116}, + } def to_representation(self, instance): data = super().to_representation(instance)