X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/9ff5f2ac22360b1ff3ef2473c15d4acfd1e7769b..refs/heads/master:/src/documents/models/chunk.py diff --git a/src/documents/models/chunk.py b/src/documents/models/chunk.py index 2698b58f..797fc174 100644 --- a/src/documents/models/chunk.py +++ b/src/documents/models/chunk.py @@ -6,7 +6,7 @@ from django.db import models from django.db.utils import IntegrityError from django.template.loader import render_to_string from django.urls import reverse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from documents.helpers import cached_in_field from documents.managers import VisibleManager from dvcs import models as dvcs_models @@ -75,8 +75,10 @@ class Chunk(dvcs_models.Document): def split(self, slug, title='', **kwargs): """ Create an empty chunk after this one """ - self.book.chunk_set.filter(number__gt=self.number).update( - number=models.F('number')+1) + # Single update makes unique constr choke on postgres. + for chunk in self.book.chunk_set.filter(number__gt=self.number).order_by('-number'): + chunk.number += 1 + chunk.save() new_chunk = None while not new_chunk: new_slug = self.book.make_chunk_slug(slug)