[scrobbles] Fix tag filtering
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
||||
@ -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">
|
||||
|
||||
Reference in New Issue
Block a user