diff --git a/api/funkwhale_api/playlists/models.py b/api/funkwhale_api/playlists/models.py index a208a5fd05e82258ad887b8f7dac06facf6f1167..f5132e12dd9d9beeb03db32090310d46b9efc6b9 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