1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

magic-removal:Management fixes. Everything works on app labels, and constraints generation is correct for mutually referential models.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1716 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams
2005-12-17 15:39:22 +00:00
parent dbd3869610
commit bb874b690a
3 changed files with 119 additions and 80 deletions

View File

@@ -14,10 +14,11 @@ from django.db.models.base import Model
from django.db.models.fields import *
from django.db.models.fields.related import *
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
from django.db.models.exceptions import FieldDoesNotExist, BadKeywordArguments
from django.db.models.signals import Signals
# Admin stages.
ADD, CHANGE, BOTH = 1, 2, 3
@@ -25,8 +26,28 @@ ADD, CHANGE, BOTH = 1, 2, 3
#def get_module(app_label, module_name):
# return __import__('%s.%s.%s' % (MODEL_PREFIX, app_label, module_name), '', '', [''])
#def get_app(app_label):
# return __import__('%s.%s' % (MODEL_PREFIX, app_label), '', '', [''])
def get_models(app):
models = []
get_models_helper(app, models)
return models
def get_models_helper(mod, seen_models):
if hasattr(mod, '_MODELS'):
seen_models.extend(mod._MODELS)
if hasattr(mod, '__all__'):
for name in mod.__all__:
sub_mod = __import__("%s.%s" % (mod.__name__, name), '','',[''])
get_models_helper(sub_mod, seen_models)
def get_app(app_label):
for app_name in settings.INSTALLED_APPS:
comps = app_name.split('.')
if app_label == comps[-1]:
app_models = __import__('%s.models' % app_name , '','',[''])
return app_models
raise ImproperlyConfigured, "App with label %s could not be found" % app_name
class LazyDate:
"""