Fixed problem of inconsistence of references

remotes/origin/enhancement/email-actions
Jesús Espino 2014-05-21 10:19:10 +02:00
parent a402e3ba40
commit e7473f7919
1 changed files with 9 additions and 7 deletions

View File

@ -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):
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)
instance.ref = refval
instance.save(update_fields=['ref'])
models.signals.post_save.connect(create_sequence, sender=Project, dispatch_uid="refproj")