Commit 2b8edca1 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

use image serialization format as defined in frontend REST API spec. refs #64

Images must be returned as object with alt property and multiple sources
for different screen sizes.
parent 73595284
Pipeline #1571 passed with stage
in 3 minutes and 21 seconds
from typing import Any
from django.db import models
from django.db.models.fields import files
from rest_framework import serializers
from audiothek.models import Audiofile, RadioReport
......@@ -55,7 +59,27 @@ class LicenseSerializer(serializers.ModelSerializer):
fields = ('name', 'identifier', 'url')
class MultiFormatImageSerializer(serializers.ImageField):
def to_representation(self, obj: files.ImageFieldFile) -> Any:
value = super().to_representation(obj)
if value is None:
return None
return {
'alt': None,
'sources': [
{'size': None,
'width': obj.width,
'height': obj.height,
'src': value}
]
}
class ProgramSerializer(serializers.ModelSerializer):
cover_image = MultiFormatImageSerializer()
class Meta:
model = RadioProgram
fields = ('id', 'name', 'description', 'teaser', 'cover_image',)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment