Add: "type" filed from mime type to PostPreviewSerializer
This commit is contained in:
parent
23c563b1f2
commit
319bb8e0f5
1 changed files with 13 additions and 1 deletions
|
@ -58,7 +58,19 @@ class PostPreviewSerializer(serializers.ModelSerializer):
|
|||
}
|
||||
|
||||
def get_media(self, obj: PostModel) -> List[Dict[str, str]]:
|
||||
return [{"type": i.mimetype, "src": i.file.url} for i in obj.files.all()]
|
||||
data = []
|
||||
for i in obj.files.all():
|
||||
if i.mimetype.startswith("video/"):
|
||||
f_type = "video"
|
||||
elif i.mimetype.startswith("image/gif"):
|
||||
f_type = "gif"
|
||||
elif i.mimetype.startswith("image/"):
|
||||
f_type = "image"
|
||||
else:
|
||||
f_type = "other"
|
||||
|
||||
data.append({"type": f_type, "mimetype": i.mimetype, "src": i.file.url})
|
||||
return data
|
||||
|
||||
def get_tags(self, obj: PostModel) -> List[str]:
|
||||
return [tag.slug for tag in obj.tags.all()]
|
||||
|
|
Loading…
Add table
Reference in a new issue