Fix progress for books with no scrobbles

This commit is contained in:
2023-03-12 16:15:20 -04:00
parent 69bdc60087
commit 34a6ac192d
2 changed files with 4 additions and 5 deletions

View File

@ -160,7 +160,10 @@ class Book(LongPlayScrobblableMixin):
"""Used to keep track of whether the book is complete or not"""
user = User.objects.get(id=user_id)
last_scrobble = get_scrobbles_for_media(self, user).last()
return int((last_scrobble.book_pages_read / self.pages) * 100)
progress = 0
if last_scrobble:
progress = int((last_scrobble.book_pages_read / self.pages) * 100)
return progress
@classmethod
def find_or_create(cls, data_dict: dict) -> "Game":