Friday, March 13, 2015

Re: Django 1.8 post_save without recursion

I don't think there's best a way of doing it but in your specific case the following should do:

@receiver(post_save, sender=Person)
def do(instance, update_fields, *args, **kwargs):
   
if update_fields == {'ok'}:
       
return
    instance
.ok = True
    instance
.save(update_fields={'ok'})

Simon

Le vendredi 13 mars 2015 01:35:46 UTC-4, Neto a écrit :
What is the best way to avoid recursion when using post_save?

@receiver(post_save, sender=Person)
def do(sender, instance, *args, **kwargs):
instance.ok = True
instance.save()

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b25d0cdf-c1ca-4229-83e2-33d863d7d03d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment