diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 1b005d1..83ed8b6 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -64,15 +64,16 @@ class ScrobbleableListView(ListView): def get_queryset(self): queryset = super().get_queryset() + user_filter = Q() if not self.request.user.is_anonymous: - queryset = queryset.annotate( + user_filter = Q(scrobble__user=self.request.user) + queryset = ( + queryset.annotate( scrobble_count=Count("scrobble"), - filter=Q(scrobble__user=self.request.user), - ).order_by("-scrobble_count") - else: - queryset = queryset.annotate( - scrobble_count=Count("scrobble") - ).order_by("-scrobble_count") + ) + .filter(user_filter, scrobble_count__gt=0) + .order_by("-scrobble_count") + ) return queryset @@ -86,7 +87,7 @@ class ScrobbleableDetailView(DetailView): if not self.request.user.is_anonymous: context_data["scrobbles"] = self.object.scrobble_set.filter( user=self.request.user - ) + ).order_by("-timestamp") return context_data @@ -201,7 +202,7 @@ class RecentScrobbleList(ListView): processed_finished__isnull=True, user=self.request.user, ) - data["counts"] = [] #scrobble_counts(user) + data["counts"] = [] # scrobble_counts(user) else: data["weekly_data"] = week_of_scrobbles() data["counts"] = scrobble_counts() diff --git a/vrobbler/templates/beers/beer_detail.html b/vrobbler/templates/beers/beer_detail.html index 7bc1b39..7bde048 100644 --- a/vrobbler/templates/beers/beer_detail.html +++ b/vrobbler/templates/beers/beer_detail.html @@ -39,7 +39,7 @@
{{object.scrobble_set.count}} scrobbles
+{{scrobbles.count}} scrobbles
@@ -55,7 +55,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}{{object.scrobble_set.count}} scrobbles
+{{scrobbles.count}} scrobbles
@@ -60,7 +60,7 @@ - {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %} + {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}{{object.scrobble_set.count}} scrobbles
-Read {{object.scrobble_set.last.book_pages_read}} pages{% if object.scrobble_set.last.long_play_complete %} and completed{% else %}{% endif %}
+{{scrobbles.count}} scrobbles
+Read {{scrobbles.last.book_pages_read}} pages{% if scrobbles.last.long_play_complete %} and completed{% else %}{% endif %}
- {% if object.scrobble_set.last.long_play_complete == True %} + {% if scrobbles.last.long_play_complete == True %} Read again {% else %} Resume reading @@ -50,7 +50,7 @@
{{object.scrobble_set.count}} scrobbles
+{{scrobbles.count}} scrobbles
{{object.scrobble_set.count}} scrobbles
+{{scrobbles.count}} scrobbles
{% if charts %}{% for chart in charts %}{{chart}}{% if forloop.last %}{% else %} | {% endif %}{% endfor %}
{% endif %} @@ -26,7 +26,7 @@ - {% for scrobble in object.scrobble_set.all %} + {% for scrobble in scrobbles.all %}{{object.scrobble_set.count}} scrobbles
+{{scrobbles.count}} scrobbles
@@ -57,7 +57,7 @@{{object.scrobble_set.count}} scrobbles
- {% if object.scrobble_set.last.long_play_seconds %} -{{object.scrobble_set.last.long_play_seconds|natural_duration}}{% if object.scrobble_set.last.long_play_complete %} and completed{% else %} spent playing{% endif %}
+{{scrobbles.count}} scrobbles
+ {% if scrobbles.last.long_play_seconds %} +{{scrobbles.last.long_play_seconds|natural_duration}}{% if scrobbles.last.long_play_complete %} and completed{% else %} spent playing{% endif %}
{% endif %}- {% if object.scrobble_set.last.long_play_complete == True %} + {% if scrobbles.last.long_play_complete == True %} Play again {% else %} Resume playing @@ -86,7 +86,7 @@