Minimal double reader.
[wolnelektury.git] / apps / catalogue / models / book.py
index e80b8af..9025e3e 100644 (file)
@@ -75,7 +75,7 @@ class Book(models.Model):
 
         self.sort_key = sortify(self.title)
 
-        ret = super(Book, self).save(force_insert, force_update)
+        ret = super(Book, self).save(force_insert, force_update, **kwargs)
 
         if reset_short_html:
             self.reset_short_html()
@@ -391,6 +391,10 @@ class Book(models.Model):
             for child in self.children.all():
                 child.parent_cover_changed()
 
+    def other_versions(self):
+        """Find other versions (i.e. in other languages) of the book."""
+        return type(self).objects.filter(common_slug=self.common_slug).exclude(pk=self.pk)
+
     def related_info(self):
         """Keeps info about related objects (tags, media) in cache field."""
         if self._related_info is not None:
@@ -511,10 +515,11 @@ class Book(models.Model):
         """
         # get relevant books and their tags
         objects = cls.tagged.with_all(tags)
+        parents = objects.filter(html_file='').only('slug')
         # eliminate descendants
         l_tags = Tag.objects.filter(category='book',
-            slug__in=[book.book_tag_slug() for book in objects.iterator()])
-        descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).iterator()]
+            slug__in=[book.book_tag_slug() for book in parents.iterator()])
+        descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).only('pk').iterator()]
         if descendants_keys:
             objects = objects.exclude(pk__in=descendants_keys)