1👍
You can quite easily have a python script that uses your models. This is what I do for example for a script that imports some external data to my database:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<path>.settings")
Where you need to replace <path>
by the name the module containing your settings. You can also copy this line from the script manage.py
One you have done it, you can import the models:
from <app>.models import *
For which you need to replace <app>
. You can then create or update models, and call save()
to update the database.
Finally, you can call this script by a cron, or better, let it run all the time, and sleep 2 seconds in a loop to update your database.
Source:stackexchange.com