[scrobbles] Fix tag filtering
Some checks failed
build & deploy / test (push) Successful in 1m53s
build & deploy / deploy (push) Has been cancelled

This commit is contained in:
2026-04-02 15:53:55 -04:00
parent df673eaccc
commit 710aff5de4
2 changed files with 21 additions and 2 deletions

View File

@ -315,12 +315,26 @@ class ScrobbleListView(LoginRequiredMixin, ListView):
if tags_param:
tag_list = [t.strip() for t in tags_param.split(",") if t.strip()]
if tag_list:
qs = qs.filter(tags__name__in=tag_list).distinct()
from django.contrib.contenttypes.models import ContentType
from taggit.models import TaggedItem
scrobble_ct = ContentType.objects.get_for_model(Scrobble)
matching_ids = list(
TaggedItem.objects.filter(
content_type=scrobble_ct,
tag__name__in=tag_list,
).values_list("object_id", flat=True)
)
qs = qs.filter(id__in=matching_ids).distinct()
else:
tag_list = []
self.tag_list = tag_list
return qs
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx["tags_param"] = self.request.GET.get("tags", "")
ctx["tag_list"] = getattr(self, "tag_list", [])
return ctx

View File

@ -5,7 +5,12 @@
{% block content %}
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">All Scrobbles</h1>
<div>
<h1 class="h2">All Scrobbles</h1>
{% if tag_list %}
<h6 class="text-muted">Tagged {{ tag_list|join:", " }}</h6>
{% endif %}
</div>
</div>
<div class="table-responsive">