Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » m2m_changed signal called multiple times? [RSS Feed]

#1 Jan. 17, 2011 10:09:50

Martin T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

m2m_changed signal called multiple times?


Hello,

I have:

* settings.py:

...
import logging

logging.basicConfig(
level = logging.DEBUG,
format = '%(asctime)s %(levelname)s %(message)s',
filename = LOG_FILE,
filemode = 'w'
)

* models.py:

class ImageSize(models.Model):
...

class Image(models.Model):
size = models.ManyToManyField(ImageSize)
...def ready_to_resize(sender, instance, action, reverse, model, pk_set,**kwargs):logging.debug("ready_to_resize called")m2m_changed.connect(ready_to_resize, sender=Image.size.through,dispatch_uid="38fy3f73")I am using Django admin interface. I insert 2 sizes into ImageSize and nowI am creating new Image record. I select both sizes and in my log I get 4times:2011-01-17 10:57:01,749 DEBUG ready_to_resize called
2011-01-17 10:57:01,751 DEBUG ready_to_resize called
2011-01-17 10:57:01,753 DEBUG ready_to_resize called
2011-01-17 10:57:01,754 DEBUG ready_to_resize calledDoes anybody know why? It is always 4 times. I can add third item intoImageSize or select only one ImageSize for Image, there are always 4records in the log.Thanks,
Martin

--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 17, 2011 10:53:14

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

m2m_changed signal called multiple times?


On 17 jan, 11:09, Martin Tiršel <dja...@blackpage.eu> wrote:

(snip)

> m2m_changed.connect(ready_to_resize, sender=Image.size.through,  
> dispatch_uid="38fy3f73")
>
> I am using Django admin interface. I insert 2 sizes into ImageSize and now  
> I am creating new Image record. I select both sizes and in my log I get 4  
> times:
>
> 2011-01-17 10:57:01,749 DEBUG ready_to_resize called
> 2011-01-17 10:57:01,751 DEBUG ready_to_resize called
> 2011-01-17 10:57:01,753 DEBUG ready_to_resize called
> 2011-01-17 10:57:01,754 DEBUG ready_to_resize called
>
> Does anybody know why? It is always 4 times.


First change your logging message to this:

def ready_to_resize(sender, instance, action, reverse, model,
pk_set,
**kwargs):
logging.debug("ready_to_resize called with action '%s'" %
action)


Then read the FineManual about m2m_changed and the meaning of the
'action' argument.http://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 17, 2011 11:08:01

Martin T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

m2m_changed signal called multiple times?


Yes, I just got it:

2011-01-17 11:57:07,389 DEBUG pre_clear
2011-01-17 11:57:07,392 DEBUG post_clear
2011-01-17 11:57:07,393 DEBUG pre_add
2011-01-17 11:57:07,395 DEBUG post_addIt is the first time I am working with signals and forget about actionargument :(But why is there pre_clear and post_clear action when I am creating a newImage record?Thanks,
MartinOn Mon, 17 Jan 2011 11:53:05 +0100, bruno desthuilliers<bruno.desthuilli...@gmail.com> wrote:On 17 jan, 11:09, Martin Tiršel <dja...@blackpage.eu> wrote:

(snip)m2m_changed.connect(ready_to_resize, sender=Image.size.through,dispatch_uid="38fy3f73")I am using Django admin interface. I insert 2 sizes into ImageSize andnow I am creating new Image record. I select both sizes and in my log Iget 4 times:2011-01-17 10:57:01,749 DEBUG ready_to_resize called
2011-01-17 10:57:01,751 DEBUG ready_to_resize called
2011-01-17 10:57:01,753 DEBUG ready_to_resize called
2011-01-17 10:57:01,754 DEBUG ready_to_resize called

Does anybody know why? It is always 4 times.First change your logging message to this:

def ready_to_resize(sender, instance, action, reverse, model,
pk_set,
**kwargs):
logging.debug("ready_to_resize called with action '%s'" %
action)


Then read the FineManual about m2m_changed and the meaning of the
'action' argument.http://docs.djangoproject.com/en/dev/ref/signals/#m2m-changed--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » m2m_changed signal called multiple times? [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support