I am writing a script to process some data, and I need to get this data from the database. I write a script not in views.py . The script is in myscript.py . I wanted to import the models, as usual in views.py , but it became mated. I rummaged in the internet, found out that if you need, for example, to work separately with ORM, in a separate file, then you need to prescribe django.setup() . But you just canβt register it as well, there you need to turn on the project settings. Please tell me how to do all this, what to register in order to work normally with ORM Django later.
Here is the project structure:
[name_project] βββ [name_project] β βββ settings β | βββ __init__.py β | βββ _django.py | βββ __init__.py β βββ urls.py β βββ wsgi.py βββ myapp β βββ models.py β βββ views.py β βββ myscript.py βββ manage.py
Settings.pynot visible. Probably beforedjango.setup()will helpos.environ.setdefault("DJANGO_SETTINGS_MODULE", "name_project.settings._django.py"). Also alternative is m9_psyImportError: No module named 'name_project'. instead ofname_projectregistered the name of your project) - SkiesXmanage.pyviamanage.py? Documentation about this - andreymal