django signals - getting it right

131 Views Asked by At

This is the first time I've used signals, and I'm utilising them as a learning curve, but I wish to make sure that I'm getting things right.

I'm utilising the post_save signal for a model (for all intents and purposes lets call it ModelA) which upon being saved I wish it to send a signal to send the data to my api app.

signals.py

def apiCall_Update(sender, **kwargs):
    ...

post_save.connect(apiCall_Update, sender=ModelA, dispatch_uid='Update')

I'm using an UpdateView to update the model in this instance

class UpdateModelA(UpdateView):
    model = ModelA
    slug_field = 'name'
    slug_url_kwarg = 'name'
    template_name_suffix = "_update_form.html"
    success_url = reverse_lazy('modela_manager')

ModelA updates perfectly fine when this view is run, however I'm not getting the post_save signal being triggered. I could be clutching at thin air here and be doing the completely wrong thing. I have tried various resources including the docs and other stacks to see if I can debug this myself, but I'm doing everything I have been reading and I am none-the-wiser as to the correct method of doing this.

1

There are 1 best solutions below

0
On BEST ANSWER

After further investigation, it seems that it was purely down to the signals not being loaded.

I achieved the result I was after, by importing the signals into the models.py that they were related to.

from myapp import signals

This applies when the signals are in their own file (I wrote them into a signals.py in the apps folder)