handle deletions in annotations ids

This commit is contained in:
j 2012-01-03 14:46:45 +05:30
parent aaa8f4f1ca
commit 9e35c3b229

View file

@ -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)