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]]:
|
def get_media(self, obj: PostModel) -> List[Dict[str, str]]:
|
||||||
data = []
|
data = []
|
||||||
for i in obj.files.all():
|
for i in obj.files.all():
|
||||||
if i.mimetype.startswith("video/"):
|
data.append(
|
||||||
f_type = "video"
|
{"type": i.file_type, "mimetype": i.mimetype, "src": i.file.url}
|
||||||
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
|
return data
|
||||||
|
|
||||||
def get_media_count(self, obj: PostModel) -> int:
|
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]]:
|
def get_media(self, obj) -> List[Dict[str, str]]:
|
||||||
data = []
|
data = []
|
||||||
for i in obj.files.all():
|
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
|
return data
|
||||||
|
|
Loading…
Add table
Reference in a new issue