I have my models in individual files:
models
\
|__init__.py
|event.py
|a_thing.py
|...
In __init__.py
I import each model and after that I set the signal handling.
For the Event
model I need some post_save
handling.
This is the truncated version of __init__.py
:
from django.db.models.signals import post_save
from django.dispatch import receiver
from core.models.event import Event
# Event
@receiver(post_save, sender = Event)
def event_post_save(sender, dispatch_uid = 'nope', **kwargs):
print kwargs.get('created')
print '------'
Whenever I save an Event
via the console the message in the post_save
is printed once but whenever I use the admin interface it gets printed twice. This may be because I import the models inside admin.py
as well.
Is there a workaround for this so that I can save Event objects from the admin interface without the post_save
firing twice?
I managed to fix it my moving the signal handling to the views' __init__.py
instead of models' __init__.py