Answer the question
In order to leave comments, you need to log in
How to work with a database in Django in a regular python file (python script.py)?
Good evening. I don't know if I can explain properly, but I'll try.
I have a multi-threaded script that does certain tasks.
I want to improve it and connect it to a file (optional) database in order to keep some records, statistics, etc.
Because I like working with django, I would like to describe the models I need in it, in fact, in the admin panel to view and manage them, but in this multi-threaded script, which is launched simply by the "python script.py" command, I need the ability to get lines from models and write, respectively.
How can this be done and is it possible?
Or is there an option to implement multi-threading in django with a long running time and manual interruption? (this option is less preferred)
Answer the question
In order to leave comments, you need to log in
import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = 'yourproject.settings'
django.setup()
# далее импортируете и используете свои джанговские модели
from yourapp.models import SomeModel
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question