Add number of tracks and discs of an album to API

This commit is contained in:
Georg Krause 2021-02-20 12:54:11 +01:00
parent b011db2bb4
commit b321ab8da2
4 changed files with 43 additions and 1 deletions

View file

@ -20,6 +20,7 @@ from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone
from django.db.models import Prefetch, Count
from funkwhale_api import musicbrainz
from funkwhale_api.common import fields
@ -420,7 +421,13 @@ def import_album(v):
class TrackQuerySet(common_models.LocalFromFidQuerySet, models.QuerySet):
def for_nested_serialization(self):
return self.prefetch_related(
"artist", "album__artist", "album__attachment_cover"
"artist",
Prefetch(
"album",
queryset=Album.objects.select_related(
"artist", "attachment_cover"
).annotate(_prefetched_tracks_count=Count("tracks")),
),
)
def annotate_playable_by_actor(self, actor):