mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
a76e91cf5a
+ remove more fields from artist, album and artist models on serializers
37 lines
709 B
Python
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]
|