CHeck for current shelves attr before querying for it

This commit is contained in:
Mouse Reeve 2021-09-27 11:17:53 -07:00
parent 995e2c47db
commit 35131262ff

View file

@ -70,6 +70,9 @@ def related_status(notification):
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def active_shelf(context, book): def active_shelf(context, book):
"""check what shelf a user has a book on, if any""" """check what shelf a user has a book on, if any"""
if hasattr(book, "current_shelves"):
return book.current_shelves[0]
shelf = ( shelf = (
models.ShelfBook.objects.filter( models.ShelfBook.objects.filter(
shelf__user=context["request"].user, shelf__user=context["request"].user,