handle deletions in annotations ids
This commit is contained in:
parent
aaa8f4f1ca
commit
9e35c3b229
1 changed files with 6 additions and 0 deletions
|
@ -48,6 +48,12 @@ class Annotation(models.Model):
|
||||||
def set_public_id(self):
|
def set_public_id(self):
|
||||||
if self.id:
|
if self.id:
|
||||||
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count() + 1
|
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count() + 1
|
||||||
|
if public_id > 1:
|
||||||
|
previous = Annotation.objects.filter(item=self.item,
|
||||||
|
id__lt=self.id).order_by('-id')[0]
|
||||||
|
if not previous.public_id:
|
||||||
|
previous.set_public_id()
|
||||||
|
public_id = ox.fromAZ(previous.public_id.split('/')[-1]) + 1
|
||||||
self.public_id = "%s/%s" % (self.item.itemId, ox.toAZ(public_id))
|
self.public_id = "%s/%s" % (self.item.itemId, ox.toAZ(public_id))
|
||||||
Annotation.objects.filter(id=self.id).update(public_id=self.public_id)
|
Annotation.objects.filter(id=self.id).update(public_id=self.public_id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue