From 9e35c3b229e383c9d6f091b62e5e1d65ee1bde29 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 3 Jan 2012 14:46:45 +0530 Subject: [PATCH] handle deletions in annotations ids --- pandora/annotation/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index d4a80946c..426294372 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -48,6 +48,12 @@ class Annotation(models.Model): def set_public_id(self): if self.id: 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)) Annotation.objects.filter(id=self.id).update(public_id=self.public_id)