diff --git a/api/funkwhale_api/audio/filters.py b/api/funkwhale_api/audio/filters.py index 6b1a9e8d9..9b7088c1d 100644 --- a/api/funkwhale_api/audio/filters.py +++ b/api/funkwhale_api/audio/filters.py @@ -35,6 +35,7 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet): fields=( ("creation_date", "creation_date"), ("artist__modification_date", "modification_date"), + ("?", "random"), ) ) diff --git a/api/funkwhale_api/music/filters.py b/api/funkwhale_api/music/filters.py index d69dd13a3..7f09924d1 100644 --- a/api/funkwhale_api/music/filters.py +++ b/api/funkwhale_api/music/filters.py @@ -1,5 +1,6 @@ from django.db.models import Q +import django_filters from django_filters import rest_framework as filters from funkwhale_api.audio import filters as audio_filters @@ -80,6 +81,15 @@ class ArtistFilter( scope = common_filters.ActorScopeFilter( actor_field="tracks__uploads__library__actor", distinct=True ) + ordering = django_filters.OrderingFilter( + fields=( + ("id", "id"), + ("name", "name"), + ("creation_date", "creation_date"), + ("modification_date", "modification_date"), + ("?", "random"), + ) + ) class Meta: model = models.Artist @@ -118,6 +128,21 @@ class TrackFilter( field_name="_", method="filter_artist", queryset=models.Artist.objects.all() ) + ordering = django_filters.OrderingFilter( + fields=( + ("creation_date", "creation_date"), + ("title", "title"), + ("album__title", "album__title"), + ("album__release_date", "album__release_date"), + ("size", "size"), + ("position", "position"), + ("disc_number", "disc_number"), + ("artist__name", "artist__name"), + ("artist__modification_date", "artist__modification_date"), + ("?", "random"), + ) + ) + class Meta: model = models.Track fields = { @@ -207,6 +232,16 @@ class AlbumFilter( actor_field="tracks__uploads__library__actor", distinct=True ) + ordering = django_filters.OrderingFilter( + fields=( + ("creation_date", "creation_date"), + ("release_date", "release_date"), + ("title", "title"), + ("artist__modification_date", "artist__modification_date"), + ("?", "random"), + ) + ) + class Meta: model = models.Album fields = ["playable", "q", "artist", "scope", "mbid"] diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index 6c9f7e41c..e38b15887 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -130,7 +130,6 @@ class ArtistViewSet( required_scope = "libraries" anonymous_policy = "setting" filterset_class = filters.ArtistFilter - ordering_fields = ("id", "name", "creation_date", "modification_date") fetches = federation_decorators.fetches_route() mutations = common_decorators.mutations_route(types=["update"]) @@ -187,12 +186,6 @@ class AlbumViewSet( permission_classes = [oauth_permissions.ScopePermission] required_scope = "libraries" anonymous_policy = "setting" - ordering_fields = ( - "creation_date", - "release_date", - "title", - "artist__modification_date", - ) filterset_class = filters.AlbumFilter fetches = federation_decorators.fetches_route() @@ -345,17 +338,6 @@ class TrackViewSet( required_scope = "libraries" anonymous_policy = "setting" filterset_class = filters.TrackFilter - ordering_fields = ( - "creation_date", - "title", - "album__title", - "album__release_date", - "size", - "position", - "disc_number", - "artist__name", - "artist__modification_date", - ) fetches = federation_decorators.fetches_route() mutations = common_decorators.mutations_route(types=["update"])