from django.db.utils import IntegrityError
from django.template.loader import render_to_string
from django.urls import reverse
from django.db.utils import IntegrityError
from django.template.loader import render_to_string
from django.urls import reverse
from documents.helpers import cached_in_field
from documents.managers import VisibleManager
from dvcs import models as dvcs_models
from documents.helpers import cached_in_field
from documents.managers import VisibleManager
from dvcs import models as dvcs_models
def split(self, slug, title='', **kwargs):
""" Create an empty chunk after this one """
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()