How to detect and respond to a database change (INSERT) from a django project?

I am setting up our project to integrate with a shipping platform called Endicia which has the ability to insert new rows into our database when a package is shipped.

How can I detect from python when a new row has been inserted?

My solution for now would be to query the DB every 30 seconds or so for new rows... is there another solution to send a signal from postgres to python?

Upvotes: 2

Views: 1037

Answers (1)

Jordan Reiter
Jordan Reiter

Reputation: 21032

You'd set up a custom command that is run by the manage.py file.

You'd put it in `yourapp/management/commands/' folder. Make sure to add an init.py file to both the management and commands folder or the command won't work. Then you create the code for the custom command.

Then, see this related question about running a shell script when changes are made to a postgres database. The answer there was to use PL/sh. You'll need to figure that part out on your own, but basically however you do it, the end result is that the script should call something like /path/to/app/manage.py command_name

Upvotes: 1

Related Questions