Fx #1178: Display channel and track downloads count

This commit is contained in:
Agate 2020-07-31 11:46:25 +02:00
parent 75f9537d89
commit e9186ca813
8 changed files with 30 additions and 3 deletions

View file

@ -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)