﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20050	Django models are not importable for utility scripts	anatoly techtonik	nobody	"`application/models.py` often use `settings.py`, and because Django can not import its own settings, an attempt to import models from ordinary command line helper script fails.


My application layout:
{{{
+ codereview/
|  + __init__.py
|  + models.py
|
+ settings.py
+ data_schema.py
}}}

`data_schema.py`
{{{
from codereview import models
}}}

And the error:
{{{
  ...
  File ""codereview\models.py"", line 676, in Account
    default_context = db.IntegerProperty(default=settings.DEFAULT_CONTEXT,
  File ""...\django-1.4.5-py2.7.egg\django\utils\functional.py"", line 184, in inner
    self._setup()
  File ""...\django-1.4.5-py2.7.egg\django\conf\__init__.py"", line 40, in _setup
    raise ImportError(""Settings cannot be imported, because environment variable %s is undefined."" % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
}}}

I know about `os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'` workaround. The questions are:

  * Why users need to specify it every time explicitly?
  * Why 'settings' is not the sane default?
  * Why this error can not be shown only after Django actually fails to find the settings?
"	Uncategorized	closed	Core (Other)	1.4	Normal	needsinfo			Unreviewed	0	0	0	0	0	1
