Question

I have the following problem: I Am using a Django framework. One of the parts in a system (non-django) writes to the database, in the same database that django is using. I want to have a signal when an object is being saved. It's a django model object but not saved via django, but directly in the mysql database.

Is there a way django can watch save-actions in his database when it's not being saved by django?

The neatest way would be: create an Api, and let the save action run through this api. The save signal can than be django default. (but this depends on some work of externals... so not the prefered route... for future development it sure is).

Another option is to implement celery and create a task that frequently looks whether one of the saved objects has had no follow up..... (also quit some puzzling I guess to get this up and running)

But there might be an easier... for me unknown? I saw django watchdog solutions for file systems... not for databases (probably because django has this build in... when properly done through django)

to complex it: I test and develop locally with sqlite .... but the save signal I can put in my tests without needing to get this locally working.... as long as it works in mysql, I Am happy.

Was it helpful?

Solution 2

In the end, I wrote an api that can be called by the thirdparty module. I delivered the code to logon on django using c-code to this api and call the GET of this api. (using django rest framework). This api just saves the object (the id given in the url), and from there on it's default django. The only thing the third party had to do is build in my code to call the api as well....

Maybe not the best solution, but the best to implement for my problem....

OTHER TIPS

You can try this solution:

  1. Create a new table 'django_watch' with one column 'object_id' (add other columns like 'created_datetime' etc according to your standards);

  2. Lets say your main table is 'object'. Add a mysql trigger for the INSERT event on this table.

  3. You should add an extra insert query inside the trigger to insert the object_id into 'django_watch' table.

  4. Now you can have a cronjob that will be inpecting the new table 'django_watch' (for updations in Django objects) and perform necessary actions. You can run this cronjob continuously with some 1 minute delay (upto you).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top