get suggested books from shelfbook

This commit is contained in:
Mouse Reeve 2020-11-06 20:51:11 -08:00
parent a02f380472
commit ba97870276
2 changed files with 7 additions and 3 deletions

View file

@ -11,7 +11,7 @@
<div class="tabs is-small"> <div class="tabs is-small">
<ul> <ul>
{% for shelf in suggested_books %} {% for shelf in suggested_books %}
{% if shelf.books.count %} {% if shelf.books %}
{% with shelf_counter=forloop.counter %} {% with shelf_counter=forloop.counter %}
<li> <li>
<p>{{ shelf.name }}</p> <p>{{ shelf.name }}</p>

View file

@ -3,7 +3,7 @@ import re
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.postgres.search import TrigramSimilarity from django.contrib.postgres.search import TrigramSimilarity
from django.db.models import Avg, Count, Q from django.db.models import Avg, Q
from django.http import HttpResponseBadRequest, HttpResponseNotFound,\ from django.http import HttpResponseBadRequest, HttpResponseNotFound,\
JsonResponse JsonResponse
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@ -67,9 +67,13 @@ def home_tab(request, tab):
for preset in preset_shelves: for preset in preset_shelves:
limit = max_books - book_count limit = max_books - book_count
shelf = request.user.shelf_set.get(identifier=preset) shelf = request.user.shelf_set.get(identifier=preset)
shelf_books = shelf.shelfbook_set.order_by(
'-updated_date'
).all()[:limit]
shelf_preview = { shelf_preview = {
'name': shelf.name, 'name': shelf.name,
'books': shelf.books.all()[:limit] 'books': [s.book for s in shelf_books]
} }
suggested_books.append(shelf_preview) suggested_books.append(shelf_preview)
book_count += len(shelf_preview['books']) book_count += len(shelf_preview['books'])