Skip to content
Snippets Groups Projects
Commit 1c7bc176 authored by Agate's avatar Agate 💬
Browse files

Merge branch '1078-play-all-album-artist' into 'master'

Fix #1078: Include tracks by album artist when filtering by artist on /api/v1/tracks

See merge request funkwhale/funkwhale!1121
parents 1638a319 798e3c03
No related branches found
No related tags found
No related merge requests found
from django.db.models import Q
from django_filters import rest_framework as filters
from funkwhale_api.audio import filters as audio_filters
......@@ -112,6 +114,9 @@ class TrackFilter(
scope = common_filters.ActorScopeFilter(
actor_field="uploads__library__actor", distinct=True
)
artist = filters.ModelChoiceFilter(
field_name="_", method="filter_artist", queryset=models.Artist.objects.all()
)
class Meta:
model = models.Track
......@@ -119,7 +124,6 @@ class TrackFilter(
"title": ["exact", "iexact", "startswith", "icontains"],
"playable": ["exact"],
"id": ["exact"],
"artist": ["exact"],
"album": ["exact"],
"license": ["exact"],
"scope": ["exact"],
......@@ -134,6 +138,9 @@ class TrackFilter(
actor = utils.get_actor_from_request(self.request)
return queryset.playable_by(actor, value).distinct()
def filter_artist(self, queryset, name, value):
return queryset.filter(Q(artist=value) | Q(album__artist=value))
class UploadFilter(audio_filters.IncludeChannelsFilterSet):
library = filters.CharFilter("library__uuid")
......
......@@ -184,3 +184,22 @@ def test_library_filter_artist(factories, queryset_equal_list, mocker, anonymous
)
assert filterset.qs == [upload.track.artist]
def test_track_filter_artist_includes_album_artist(
factories, mocker, queryset_equal_list, anonymous_user
):
factories["music.Track"]()
track1 = factories["music.Track"]()
track2 = factories["music.Track"](
album__artist=track1.artist, artist=factories["music.Artist"]()
)
qs = models.Track.objects.all()
filterset = filters.TrackFilter(
{"artist": track1.artist.pk},
request=mocker.Mock(user=anonymous_user),
queryset=qs,
)
assert filterset.qs == [track2, track1]
Include tracks by album artist when filtering by artist on /api/v1/tracks (#1078)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment