Skip to content
Advertisement

Django: how to write django signal to update field in django?

i want to write a simple django signal that would automatically change the status of a field from live to finished, when i check a button completed.

I have a model that looks like this

JavaScript

when i check the won button that is in the PredictionData model, i want to immediately changes the status of the Prediction to finished.

NOTE: i have some tuple at the top of the model.

JavaScript

Advertisement

Answer

You can make a signal with:

JavaScript

Note: Signals are often not a robust mechanism. I wrote an article [Django-antipatterns] that discusses certain problems when using signals. Therefore you should use them only as a last resort.


Note: normally a Django model is given a singular name, so Prediction instead of Predictions.

Advertisement