0

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?

1
  • you can probably write a data migration to read from file and load into DB which will then be used by django. Commented Aug 19, 2019 at 13:34

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You could also use this https://github.com/kraiz/django-crontab

That makes it even more simple to use

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.