From 7e9320fc1c8e97f319d4b20e6a4ada7441b52338 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 8 May 2018 23:06:29 +0200 Subject: [PATCH] Queryset methods for playlists --- api/funkwhale_api/playlists/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/funkwhale_api/playlists/models.py b/api/funkwhale_api/playlists/models.py index a208a5fd0..f5132e12d 100644 --- a/api/funkwhale_api/playlists/models.py +++ b/api/funkwhale_api/playlists/models.py @@ -9,6 +9,12 @@ from funkwhale_api.common import fields from funkwhale_api.common import preferences +class PlaylistQuerySet(models.QuerySet): + def with_tracks_count(self): + return self.annotate( + _tracks_count=models.Count('playlist_tracks')) + + class Playlist(models.Model): name = models.CharField(max_length=50) user = models.ForeignKey( @@ -18,6 +24,8 @@ class Playlist(models.Model): auto_now=True) privacy_level = fields.get_privacy_field() + objects = PlaylistQuerySet.as_manager() + def __str__(self): return self.name