Or rather, I have the old double-import problem with Django and signals when i include the signals.py from models.py
I’d rather not have to put the “run only once” code in for the signals, but i might do that if i absolutely have to. It just seems like such a stupid hack.
Anyway,
given i have a signals.py file AND one of the signals is for one of the objects defined in models.py, HOW do i create the annotation for it?
If i include the model then i get the ol’ “circular reference” problem that Python, confusingly, still seems to be tripped up by. It is only 2012 though.
I experimented with using get_model, but that doesn’t seem to work… the signal is now called for all saves on any and all models in the models.py file.
Here is the annotation, and what it looks like now:
@receiver(pre_save, sender=get_model('myapp.models','Story'))
i also tried
@receiver(pre_save, sender=Story)
with a corresponding from myapp.models import Story above, but caused the import error described.
What do i do?
When stuck like this, I just register the receiver without specifying a sender, and do the model import inside the function body.