mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 13:09:16 +02:00
Fx #1178: Display channel and track downloads count
This commit is contained in:
parent
75f9537d89
commit
e9186ca813
8 changed files with 30 additions and 3 deletions
|
@ -7,7 +7,7 @@ from rest_framework import viewsets
|
|||
|
||||
from django import http
|
||||
from django.db import transaction
|
||||
from django.db.models import Count, Prefetch, Q
|
||||
from django.db.models import Count, Prefetch, Q, Sum
|
||||
from django.utils import timezone
|
||||
|
||||
from funkwhale_api.common import locales
|
||||
|
@ -93,6 +93,14 @@ class ChannelViewSet(
|
|||
return serializers.ChannelUpdateSerializer
|
||||
return serializers.ChannelCreateSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
if self.action == "retrieve":
|
||||
queryset = queryset.annotate(
|
||||
_downloads_count=Sum("artist__tracks__downloads_count")
|
||||
)
|
||||
return queryset
|
||||
|
||||
def perform_create(self, serializer):
|
||||
return serializer.save(attributed_to=self.request.user.actor)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue