mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-24 19:23:44 +03:00
Compare commits
No commits in common. "b16ec214868a7bd1388bb7ca03880aea5c5a51d5" and "127b4b6e115bd376339cd5be9b11252f7058601d" have entirely different histories.
b16ec21486
...
127b4b6e11
|
@ -239,26 +239,10 @@ class Meta:
|
||||||
|
|
||||||
class FullAlbumSerializer(serializers.ModelSerializer):
|
class FullAlbumSerializer(serializers.ModelSerializer):
|
||||||
songs = ListSongSerializer(many=True, read_only=True)
|
songs = ListSongSerializer(many=True, read_only=True)
|
||||||
artists = serializers.SerializerMethodField("get_artists")
|
|
||||||
|
|
||||||
@extend_schema_field(AuthorSerializer(many=True))
|
|
||||||
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(
|
|
||||||
artists,
|
|
||||||
many=True,
|
|
||||||
).data
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Album
|
model = Album
|
||||||
fields = ["name", "link", "image", "songs", "artists"]
|
fields = ["name", "link", "image", "songs"]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"link": {"read_only": True},
|
"link": {"read_only": True},
|
||||||
"image": {"read_only": True},
|
"image": {"read_only": True},
|
||||||
|
@ -267,27 +251,10 @@ class Meta:
|
||||||
|
|
||||||
class FullAuthorSerializer(serializers.ModelSerializer):
|
class FullAuthorSerializer(serializers.ModelSerializer):
|
||||||
songs = ListSongSerializer(many=True, read_only=True)
|
songs = ListSongSerializer(many=True, read_only=True)
|
||||||
albums = serializers.SerializerMethodField(method_name="get_albums")
|
|
||||||
|
|
||||||
@extend_schema_field(AlbumSerializer(many=True))
|
|
||||||
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(
|
|
||||||
albums,
|
|
||||||
many=True,
|
|
||||||
).data
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Author
|
model = Author
|
||||||
fields = ["name", "link", "image", "songs", "albums"]
|
fields = ["name", "link", "image", "songs"]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"link": {"read_only": True},
|
"link": {"read_only": True},
|
||||||
"image": {"read_only": True},
|
"image": {"read_only": True},
|
||||||
|
|
|
@ -272,7 +272,9 @@ class ListAlbumsAPIView(generics.ListAPIView):
|
||||||
serializer_class = AlbumSerializer
|
serializer_class = AlbumSerializer
|
||||||
pagination_class = StandardResultsSetPagination
|
pagination_class = StandardResultsSetPagination
|
||||||
permission_classes = [permissions.AllowAny]
|
permission_classes = [permissions.AllowAny]
|
||||||
queryset = Album.objects.cache().all()
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return Album.objects.all()
|
||||||
|
|
||||||
|
|
||||||
class RetrieveUpdateDestroyAlbumAPIView(
|
class RetrieveUpdateDestroyAlbumAPIView(
|
||||||
|
@ -282,14 +284,15 @@ class RetrieveUpdateDestroyAlbumAPIView(
|
||||||
lookup_url_kwarg = "slug"
|
lookup_url_kwarg = "slug"
|
||||||
permission_classes = [IsAdminOrReadOnly]
|
permission_classes = [IsAdminOrReadOnly]
|
||||||
serializer_class = FullAlbumSerializer
|
serializer_class = FullAlbumSerializer
|
||||||
queryset = Album.objects.cache().all()
|
|
||||||
|
|
||||||
|
|
||||||
class ListAuthorsAPIView(generics.ListAPIView):
|
class ListAuthorsAPIView(generics.ListAPIView):
|
||||||
serializer_class = AuthorSerializer
|
serializer_class = AuthorSerializer
|
||||||
pagination_class = StandardResultsSetPagination
|
pagination_class = StandardResultsSetPagination
|
||||||
permission_classes = [permissions.AllowAny]
|
permission_classes = [permissions.AllowAny]
|
||||||
queryset = Author.objects.cache().all()
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return Author.objects.all()
|
||||||
|
|
||||||
|
|
||||||
class RetrieveUpdateDestroyAuthorAPIView(
|
class RetrieveUpdateDestroyAuthorAPIView(
|
||||||
|
@ -299,7 +302,6 @@ class RetrieveUpdateDestroyAuthorAPIView(
|
||||||
lookup_url_kwarg = "slug"
|
lookup_url_kwarg = "slug"
|
||||||
permission_classes = [IsAdminOrReadOnly]
|
permission_classes = [IsAdminOrReadOnly]
|
||||||
serializer_class = FullAuthorSerializer
|
serializer_class = FullAuthorSerializer
|
||||||
queryset = Author.objects.cache().all()
|
|
||||||
|
|
||||||
|
|
||||||
class ListenSongAPIView(generics.GenericAPIView):
|
class ListenSongAPIView(generics.GenericAPIView):
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
"blog.post": {"ops": ("fetch", "get"), "timeout": 20 * 15},
|
"blog.post": {"ops": ("fetch", "get"), "timeout": 20 * 15},
|
||||||
"themes.theme": {"ops": ("fetch", "get"), "timeout": 60 * 60},
|
"themes.theme": {"ops": ("fetch", "get"), "timeout": 60 * 60},
|
||||||
"gallery.*": {"ops": ("fetch", "get", "list"), "timeout": 60 * 15},
|
"gallery.*": {"ops": ("fetch", "get", "list"), "timeout": 60 * 15},
|
||||||
"files.*": {"ops": ("fetch", "get", "list"), "timeout": 60},
|
"files.*": {"ops": ("fetch", "get"), "timeout": 60},
|
||||||
"auth.permission": {"ops": "all", "timeout": 60 * 15},
|
"auth.permission": {"ops": "all", "timeout": 60 * 15},
|
||||||
"music.*": {"ops": ("fetch", "get", "list"), "timeout": 60 * 15},
|
"music.*": {"ops": ("fetch", "get", "list"), "timeout": 60 * 15},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user