From: Radek Czajka Date: Tue, 28 Jan 2025 12:53:20 +0000 (+0100) Subject: fix for postgres X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain fix for postgres --- diff --git a/src/documents/models/chunk.py b/src/documents/models/chunk.py index 4d8f6d23..797fc174 100644 --- a/src/documents/models/chunk.py +++ b/src/documents/models/chunk.py @@ -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)