X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d019a9b5e928dcf777852d0c8d5413fd3d69b4dd..e2a460b0a960df9482701ab10ec135a5cc3c69ac:/src/catalogue/models/book.py?ds=sidebyside diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index ab7a59106..ee8595588 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -912,7 +912,10 @@ class Book(models.Model): fragments = Fragment.objects.filter(book__ancestor=self).order_by() fragments_count = fragments.count() if fragments_count: - offset = randint(0, fragments_count - number) + if fragments_count > number: + offset = randint(0, fragments_count - number) + else: + offset = 0 return fragments[offset : offset + number] elif self.parent: return self.parent.choose_fragments(number)