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?
It's probably from Django/Python import silliness. You need dispatch_uid
like you have, but I think it needs to be an argument to the decorator, not the handler itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With