Merge remote-tracking branch 'zawadzki/new-design'
[wolnelektury.git] / src / catalogue / models / book.py
index ab7a591..ee85955 100644 (file)
@@ -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)