From e7473f7919ea92015495faa99a138b833b091467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 21 May 2014 10:19:10 +0200 Subject: [PATCH] Fixed problem of inconsistence of references --- taiga/projects/references/models.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/taiga/projects/references/models.py b/taiga/projects/references/models.py index 7b2dfcce..96b2c335 100644 --- a/taiga/projects/references/models.py +++ b/taiga/projects/references/models.py @@ -56,14 +56,16 @@ def create_sequence(sender, instance, created, **kwargs): if not seq.exists(seqname): seq.create(seqname) -def attach_sequence(sender, instance, **kwargs): - # Create a reference object. This operation should be - # used in transaction context, otherwise it can - # create a lot of phantom reference objects. - refval, _ = make_reference(instance, instance.project) +def attach_sequence(sender, instance, created, **kwargs): + if created: + # Create a reference object. This operation should be + # used in transaction context, otherwise it can + # create a lot of phantom reference objects. + refval, _ = make_reference(instance, instance.project) - # Additionally, attach sequence number to instance as ref - sender.objects.filter(pk=instance.pk).update(ref=refval) + # Additionally, attach sequence number to instance as ref + instance.ref = refval + instance.save(update_fields=['ref']) models.signals.post_save.connect(create_sequence, sender=Project, dispatch_uid="refproj")