[books] Update widget to show all scrobbles WITH complete status
This commit is contained in:
@ -1144,9 +1144,32 @@ class EmbeddableTopBooksWidget(BaseEmbeddableWidget):
|
||||
media_type = "Books"
|
||||
count_label = "reads"
|
||||
no_data_message = "No books read"
|
||||
scrobble_filter = {"scrobble__long_play_complete": True}
|
||||
|
||||
def get_items(self, user, start_date):
|
||||
from books.models import Book
|
||||
from django.db.models import Count, Exists, OuterRef
|
||||
|
||||
return super().get_items(user, start_date, Book)
|
||||
completed_subquery = Book.objects.filter(
|
||||
scrobble__user=user,
|
||||
scrobble__timestamp__gte=start_date,
|
||||
scrobble__long_play_complete=True,
|
||||
pk=OuterRef("pk"),
|
||||
)
|
||||
|
||||
queryset = (
|
||||
Book.objects.filter(
|
||||
scrobble__user=user,
|
||||
scrobble__timestamp__gte=start_date,
|
||||
)
|
||||
.annotate(
|
||||
count=Count("scrobble", distinct=True),
|
||||
is_completed=Exists(completed_subquery),
|
||||
)
|
||||
.order_by("-count")[:10]
|
||||
)
|
||||
|
||||
items = list(queryset)
|
||||
for item in items:
|
||||
if not hasattr(item, "name") and hasattr(item, "title"):
|
||||
item.name = item.title
|
||||
return items
|
||||
|
||||
Reference in New Issue
Block a user