X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/d816e45e483da784b5e75ee8ca3058edf7884c7b..bbc5bd6a7c8280758a2388ebffec26e0afc35d00:/apps/catalogue/models/book.py diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index 71547755..13be963d 100755 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -209,6 +209,18 @@ class Book(models.Model): assert not other.chunk_set.exists() other.delete() + def split(self): + """Splits all the chunks into separate books.""" + self.title + for chunk in self: + book = Book.objects.create(title=chunk.title, slug=chunk.slug, + public=self.public, gallery=self.gallery) + book[0].delete() + chunk.book = book + chunk.number = 1 + chunk.save() + assert not self.chunk_set.exists() + self.delete() # State & cache # ============= @@ -271,7 +283,8 @@ class Book(models.Model): def get_on_track(self): if self.published: return -1 - stages = [ch.stage.ordering for ch in self if ch.stage is not None] + stages = [ch.stage.ordering if ch.stage is not None else 0 + for ch in self] if not len(stages): return 0 return min(stages)