Refatror: to use the filetype field
This commit is contained in:
parent
f7bc6f4d5c
commit
bbf72ab145
1 changed files with 6 additions and 11 deletions
|
@ -62,16 +62,9 @@ class PostPreviewSerializer(serializers.ModelSerializer):
|
|||
def get_media(self, obj: PostModel) -> List[Dict[str, str]]:
|
||||
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})
|
||||
data.append(
|
||||
{"type": i.file_type, "mimetype": i.mimetype, "src": i.file.url}
|
||||
)
|
||||
return data
|
||||
|
||||
def get_media_count(self, obj: PostModel) -> int:
|
||||
|
@ -142,5 +135,7 @@ class PostSerializer(serializers.ModelSerializer):
|
|||
def get_media(self, obj) -> List[Dict[str, str]]:
|
||||
data = []
|
||||
for i in obj.files.all():
|
||||
data.append({"type": i.mimetype, "url": i.file.url})
|
||||
data.append(
|
||||
{"type": i.file_type, "mimetype": i.mimetype, "src": i.file.url}
|
||||
)
|
||||
return data
|
||||
|
|
Loading…
Add table
Reference in a new issue