Files
swingmusic-extended/app/serializers/artist.py
T
cwilvx a76e91cf5a fix: duplication of artist albums on album/from-artist
+ remove more fields from artist, album and artist models on serializers
2024-07-05 04:43:39 +03:00

37 lines
709 B
Python

from dataclasses import asdict
from app.models.artist import Artist
def serialize_for_card(artist: Artist):
try:
artist_dict = asdict(artist)
except TypeError:
return {}
props_to_remove = {
"is_favorite",
"trackcount",
"duration",
"albumcount",
"playcount",
"playduration",
"playcount",
"lastplayed",
"id",
"genres",
"genrehashes",
"extra",
"created_date",
"date",
}
for key in props_to_remove:
artist_dict.pop(key, None)
return artist_dict
def serialize_for_cards(artists: list[Artist]):
return [serialize_for_card(a) for a in artists]