Suggest recently edited books if we're out of user books

This commit is contained in:
Mouse Reeve
2021-01-31 10:56:40 -08:00
parent 1a4c53da2c
commit 1e9189d43c
3 changed files with 20 additions and 12 deletions

View File

@ -55,11 +55,19 @@ class List(View):
suggestions = request.user.shelfbook_set.filter(
~Q(book__in=book_list.books.all())
)
suggestions = [s.book for s in suggestions[:5]]
if len(suggestions) < 5:
suggestions += [s.default_edition for s in \
models.Work.objects.filter(
~Q(editions__in=book_list.books.all()),
).order_by('-updated_date')
][:5 - len(suggestions)]
data = {
'title': '%s | Lists' % book_list.name,
'list': book_list,
'suggested_books': [s.book for s in suggestions[:5]],
'suggested_books': suggestions,
'list_form': forms.ListForm(instance=book_list),
}
return TemplateResponse(request, 'lists/list.html', data)