X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/a4750ca6ad789432fffd60266a38b8586994c3d6..bbc5bd6a7c8280758a2388ebffec26e0afc35d00:/apps/catalogue/models/book.py diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index 89c6267c..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 # =============