Reputation: 155
I'm working on a platform that uses Django and Django REST Framework, so this platform is used to monitor the state of some sensors which send data to the computer.
Now I have the data in the computer, and I want to create a Python file to read the data from the computer and store it in a MySQL database that Django will read and show to the user.
I have two questions:
Can I make Django read from the file, save the data in the database, and show it in the user interface?
If not, how could I make a script to run in the background when I start the project?
Upvotes: 0
Views: 164
Reputation: 37
You could also use this https://github.com/kraiz/django-crontab
That makes it even more simple to use
Upvotes: 1
Reputation: 1859
Can i make django read from the file save the data in the database
Yes, you could create a management command for this which could be run from crontab. Or create a sort of 'daemonized' version which keep on running but sleeps for X amount of seconds before running again. This command reads the data, puts it into the database.
show it in the user interface ?
Yes, but I would advise against doing this sequential (as in, don't put your 'data reading' in your view!!). So your managment command updates the database with the latest data and you view only shows the latest data.
Upvotes: 2