Ticket #1796: django-m2m-kludge.py

File django-m2m-kludge.py, 918 bytes (added by jason.mcvetta@…, 17 years ago)

Workaround for stand-alone scripts, provided by Ben Slavin on django-users

Line 
1################################################################################
2# Django M2M Kludge -- MUST BE LOADED FIRST!
3#
4# Courtesy of Benjamin Slavin on the django-users mailing list
5################################################################################
6import os
7os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
8try:
9    import settings # Assumed to be in the same directory.
10except ImportError:
11    import sys
12    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
13    sys.exit(1)
14from django.core.management import setup_environ
15from django.db.models.loading import get_models
16if __name__ == "__main__":
17        setup_environ(settings)
18loaded_models = get_models()
19################################################################################
Back to Top