Question:
How to make a code executed after an entry is inserted, removed or updated?

Problem:

I want some code to be executed after every change in the database in a specific table. Meaning, if an entry was inserted, removed or updated.


I found this >https://stackoverflow.com/a/15712353/2813152 using django signals. Is this the recommended way for this?


Can I use it for any changes at this table? Not just when an instance is saved?

Can the code run async in the background?


Solution:

Django signals are not asynchronous. But you can trigger a background job via a signal with e.g. >celery if you have code that takes some more time to complete.


As per >Django documentation, the django.db.models.signals.post_save signal has an argument created which you can use to find out if an object has been added or changed.


Get an overview of all >built-in model signals in Django.


Answered by: >Marco

Credit: >Stackoverflow


Suggested reads:

>How to solve the issue of producing the wrong output value in PHP?

>How to solve XGBoost model training fails in Python

>How to Upload files and JSON data in the same request with Angular?

>How to Use RTK Queries in a React App?

>How you can create array with associative array in other array php?

>How you can send email from a shared inbox in Python

>How you can Show or hide elements in React?


Ritu Singh

Ritu Singh

Submit
0 Answers