Question about post_save

30 views
Skip to first unread message

Neto

unread,
Aug 14, 2014, 2:12:01 AM8/14/14
to django...@googlegroups.com
I'm using post_save but he is in loop:

@receiver(models.signals.post_save, sender=Cars)
def auto_num_on_save(sender, instance, **kwargs):
    ....my code
    instance.save()


How do I save changes without calling post_save again?

Johannes Schneider

unread,
Aug 14, 2014, 3:21:36 AM8/14/14
to django...@googlegroups.com
Is there any reason why this has to happen after saving? otherwise you
could use pre_save.

bg,
Johannes
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@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/91745299-16fe-477a-b532-f2580e806d91%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/91745299-16fe-477a-b532-f2580e806d91%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Johannes Schneider
Webentwicklung
johannes....@galileo-press.de
Tel.: +49.228.42150.xxx

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn

Collin Anderson

unread,
Aug 14, 2014, 10:11:58 AM8/14/14
to django...@googlegroups.com
@receiver(models.signals.post_save, sender=Cars)
def auto_num_on_save(sender, instance, **kwargs):

   
if hasattr(instance, '_already_ran'):
       
return
   
....my code
    instance
._already_ran = True
    instance
.save()



Reply all
Reply to author
Forward
0 new messages