I am attaching a method to the post_save signal of my Django model. This way I can clear some cached items whenever the model is modified.
The problem I am having is that the signal is being triggered twice when the model is saved. It doesn't necessarily hurt anything (the code will just gracefully error out) but it can't be right.
A quick example, just printing the model to the console (using the dev server):
from blog.models import Post
from django.db.models import signals
def purge_cache(sender, **kwargs):
print 'Purging %s' % sender
signals.post_save.connect(purge_cache, sender=Post)
This is using the stable 1.1.1 release of Django.
Updated Information:
With feedback from everyone's comments, I have modified my question because the issue is now discovering why the post_save is being triggered twice. My guess at the moment is that my models.py code is imported twice and that the post_save is getting connected multiple times.
What would be the best way to figure out why it is being imported/ran twice?