Django signals - correct

This is the first time I've used signals and I'm using them as a learning curve, but I want to make sure everything is correct.

I am using the post_save signal for the model (for all intents and purposes lets call it ModelA

) which after saving I want it to send a signal to send data to my api app.

signals.py

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

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

      

I am using UpdateView to update the model on 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

refreshes fine when this view starts, however I am not getting the post_save signal. I could grab my breath here and do the completely wrong thing. I've tried various resources, including docs and other stacks, to check if I can debug this myself, but I'm doing everything I've read and I don't know how to do it right.

+3


source to share


1 answer


Upon further investigation, it appears that it was clean until the signals were loaded.

I achieved the result I was after by importing the signals into the models.py they were associated with.



from myapp import signals

      

This applies when signals are in their own file (I wrote them to signal.py in my applications folder)

+1


source







All Articles