Django model access from custom file

Can I receive access to Model from some custom file. For example I create folder in my project with name Bot. Create some, in current file call model from other app. For example:

from trading.models import Values

Then I get an error:

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Also try solution like this in my

import os
import django
os.environ["DJANGO_SETTINGS_MODULE"] = 'trading.settings'

But still doesn't work.

You don't need to do any fancy stuff from within the file, just create it in your app module (folder) and import any model you want, exactly as in the example you provided.

Back to Top