mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 13:16:33 +03:00
fixed music artist and albums relations
This commit is contained in:
parent
18ba02caab
commit
b16ec21486
|
@ -243,10 +243,16 @@ class FullAlbumSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
@extend_schema_field(AuthorSerializer(many=True))
|
@extend_schema_field(AuthorSerializer(many=True))
|
||||||
def get_artists(self, obj):
|
def get_artists(self, obj):
|
||||||
|
artists = []
|
||||||
|
qs = Author.objects.cache().filter(
|
||||||
|
songs__id__in=obj.songs.cache().all().values("id").distinct()
|
||||||
|
)
|
||||||
|
for artist in qs:
|
||||||
|
if artist not in artists:
|
||||||
|
artists.append(artist)
|
||||||
|
|
||||||
return AuthorSerializer(
|
return AuthorSerializer(
|
||||||
Author.objects.cache().filter(
|
artists,
|
||||||
songs__id__in=obj.songs.cache().all().values("id")
|
|
||||||
),
|
|
||||||
many=True,
|
many=True,
|
||||||
).data
|
).data
|
||||||
|
|
||||||
|
@ -265,10 +271,17 @@ class FullAuthorSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
@extend_schema_field(AlbumSerializer(many=True))
|
@extend_schema_field(AlbumSerializer(many=True))
|
||||||
def get_albums(self, obj):
|
def get_albums(self, obj):
|
||||||
|
qs = Album.objects.cache().filter(
|
||||||
|
songs__id__in=obj.songs.cache().all().values("id").distinct()
|
||||||
|
)
|
||||||
|
albums = []
|
||||||
|
for album in qs:
|
||||||
|
# TODO: rewrite to filter
|
||||||
|
if album not in albums:
|
||||||
|
albums.append(album)
|
||||||
|
|
||||||
return AlbumSerializer(
|
return AlbumSerializer(
|
||||||
Album.objects.cache().filter(
|
albums,
|
||||||
songs__id__in=obj.songs.cache().all().values("id")
|
|
||||||
),
|
|
||||||
many=True,
|
many=True,
|
||||||
).data
|
).data
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user