1
Django must configure all installed applications before you can use any models. To do this you must call django.setup()
import django
django.setup()
This function is called automatically:
- When running an HTTP server via Django’s WSGI support.
- When invoking a management command.
It must be called explicitly in other cases, for instance in plain Python scripts.
Source:stackexchange.com