Verified Commit 37ff297f authored by Agate's avatar Agate 💬

See #170: can now filter playlists by track, artist and album

parent 27801ce5
......@@ -2,6 +2,7 @@ from django.db.models import Count
from django_filters import rest_framework as filters
from funkwhale_api.common import filters as common_filters
from funkwhale_api.music import models as music_models
from funkwhale_api.music import utils
from . import models
......@@ -10,6 +11,21 @@ from . import models
class PlaylistFilter(filters.FilterSet):
q = filters.CharFilter(field_name="_", method="filter_q")
playable = filters.BooleanFilter(field_name="_", method="filter_playable")
track = filters.ModelChoiceFilter(
"playlist_tracks__track",
queryset=music_models.Track.objects.all(),
distinct=True,
)
album = filters.ModelChoiceFilter(
"playlist_tracks__track__album",
queryset=music_models.Album.objects.all(),
distinct=True,
)
artist = filters.ModelChoiceFilter(
"playlist_tracks__track__artist",
queryset=music_models.Artist.objects.all(),
distinct=True,
)
scope = common_filters.ActorScopeFilter(actor_field="user__actor", distinct=True)
class Meta:
......
from funkwhale_api.playlists import filters
from funkwhale_api.playlists import models
def test_playlist_filter_track(factories, queryset_equal_list):
plt = factories["playlists.PlaylistTrack"]()
factories["playlists.PlaylistTrack"]()
qs = models.Playlist.objects.all()
filterset = filters.PlaylistFilter({"track": plt.track.pk}, queryset=qs)
assert filterset.qs == [plt.playlist]
def test_playlist_filter_album(factories, queryset_equal_list):
plt = factories["playlists.PlaylistTrack"]()
factories["playlists.PlaylistTrack"]()
qs = models.Playlist.objects.all()
filterset = filters.PlaylistFilter({"album": plt.track.album.pk}, queryset=qs)
assert filterset.qs == [plt.playlist]
def test_playlist_filter_artist(factories, queryset_equal_list):
plt = factories["playlists.PlaylistTrack"]()
factories["playlists.PlaylistTrack"]()
qs = models.Playlist.objects.all()
filterset = filters.PlaylistFilter({"artist": plt.track.artist.pk}, queryset=qs)
assert filterset.qs == [plt.playlist]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment