mirror of
https://github.com/django/django.git
synced 2025-06-17 01:19:12 +00:00
Allow importing of nested model modules.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1663 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a57b462757
commit
9701daeb72
@ -15,7 +15,6 @@ class AdminApplistNode(template.Node):
|
|||||||
for app in models.get_installed_model_modules():
|
for app in models.get_installed_model_modules():
|
||||||
app_label = app.__name__[app.__name__.rindex('.')+1:]
|
app_label = app.__name__[app.__name__.rindex('.')+1:]
|
||||||
has_module_perms = user.has_module_perms(app_label)
|
has_module_perms = user.has_module_perms(app_label)
|
||||||
|
|
||||||
if has_module_perms:
|
if has_module_perms:
|
||||||
model_list = []
|
model_list = []
|
||||||
for m in app._MODELS:
|
for m in app._MODELS:
|
||||||
|
@ -371,8 +371,7 @@ def init():
|
|||||||
"Initializes the database with auth and core."
|
"Initializes the database with auth and core."
|
||||||
try:
|
try:
|
||||||
from django.db import backend, connection, models
|
from django.db import backend, connection, models
|
||||||
auth = models.get_app('auth')
|
from django.models import auth, core
|
||||||
core = models.get_app('core')
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth):
|
for sql in get_sql_create(core) + get_sql_create(auth) + get_sql_initial_data(core) + get_sql_initial_data(auth):
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
@ -642,8 +641,8 @@ def get_validation_errors(outfile):
|
|||||||
e = ModelErrorCollection(outfile)
|
e = ModelErrorCollection(outfile)
|
||||||
module_list = models.get_installed_model_modules()
|
module_list = models.get_installed_model_modules()
|
||||||
for module in module_list:
|
for module in module_list:
|
||||||
for mod in module._MODELS:
|
for cls in module._MODELS:
|
||||||
opts = mod._meta
|
opts = cls._meta
|
||||||
|
|
||||||
# Do field-specific validation.
|
# Do field-specific validation.
|
||||||
for f in opts.fields:
|
for f in opts.fields:
|
||||||
@ -690,8 +689,8 @@ def get_validation_errors(outfile):
|
|||||||
for fn in opts.admin.list_display:
|
for fn in opts.admin.list_display:
|
||||||
try:
|
try:
|
||||||
f = opts.get_field(fn)
|
f = opts.get_field(fn)
|
||||||
except models.FieldDoesNotExist:
|
except models.FieldDoesNotExist:
|
||||||
if not hasattr(mod, fn) or not callable(getattr(mod, fn)):
|
if not hasattr(cls, fn) or not callable(getattr(cls, fn)):
|
||||||
e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn)
|
e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn)
|
||||||
else:
|
else:
|
||||||
if isinstance(f, models.ManyToManyField):
|
if isinstance(f, models.ManyToManyField):
|
||||||
|
@ -69,13 +69,14 @@ def orderlist2sql(order_list, opts, prefix=''):
|
|||||||
output.append('%s%s ASC' % (prefix, backend.quote_name(orderfield2column(f, opts))))
|
output.append('%s%s ASC' % (prefix, backend.quote_name(orderfield2column(f, opts))))
|
||||||
return ', '.join(output)
|
return ', '.join(output)
|
||||||
|
|
||||||
def get_module(app_label, module_name):
|
#def get_module(app_label, module_name):
|
||||||
return __import__('%s.%s.%s' % (MODEL_PREFIX, app_label, module_name), '', '', [''])
|
# return __import__('%s.%s.%s' % (MODEL_PREFIX, app_label, module_name), '', '', [''])
|
||||||
|
|
||||||
def get_app(app_label):
|
#def get_app(app_label):
|
||||||
return __import__('%s.%s' % (MODEL_PREFIX, app_label), '', '', [''])
|
# return __import__('%s.%s' % (MODEL_PREFIX, app_label), '', '', [''])
|
||||||
|
|
||||||
_installed_models_cache = None
|
_installed_models_cache = None
|
||||||
|
|
||||||
def get_installed_models():
|
def get_installed_models():
|
||||||
"""
|
"""
|
||||||
Returns a list of installed "models" packages, such as foo.models,
|
Returns a list of installed "models" packages, such as foo.models,
|
||||||
@ -88,11 +89,19 @@ def get_installed_models():
|
|||||||
for a in settings.INSTALLED_APPS:
|
for a in settings.INSTALLED_APPS:
|
||||||
try:
|
try:
|
||||||
_installed_models_cache.append(__import__(a + '.models', '', '', ['']))
|
_installed_models_cache.append(__import__(a + '.models', '', '', ['']))
|
||||||
except ImportError:
|
except ImportError, e:
|
||||||
pass
|
pass
|
||||||
return _installed_models_cache
|
return _installed_models_cache
|
||||||
|
|
||||||
_installed_modules_cache = None
|
_installed_modules_cache = None
|
||||||
|
|
||||||
|
def add_model_module(mod, modules):
|
||||||
|
if hasattr(mod, '_MODELS'):
|
||||||
|
modules.append(mod)
|
||||||
|
for name in getattr(mod, '__all__', []):
|
||||||
|
submod = __import__("%s.%s" % ( mod.__name__, name),'','',[''])
|
||||||
|
add_model_module(submod, modules)
|
||||||
|
|
||||||
def get_installed_model_modules(core_models=None):
|
def get_installed_model_modules(core_models=None):
|
||||||
"""
|
"""
|
||||||
Returns a list of installed models, such as django.models.core,
|
Returns a list of installed models, such as django.models.core,
|
||||||
@ -107,12 +116,7 @@ def get_installed_model_modules(core_models=None):
|
|||||||
for submodule in (core_models or []):
|
for submodule in (core_models or []):
|
||||||
_installed_modules_cache.append(__import__('django.models.%s' % submodule, '', '', ['']))
|
_installed_modules_cache.append(__import__('django.models.%s' % submodule, '', '', ['']))
|
||||||
for mod in get_installed_models():
|
for mod in get_installed_models():
|
||||||
try:
|
add_model_module(mod, _installed_modules_cache)
|
||||||
mod._MODELS
|
|
||||||
except AttributeError:
|
|
||||||
pass # Skip model modules that don't actually have models in them.
|
|
||||||
else:
|
|
||||||
_installed_modules_cache.append(mod)
|
|
||||||
return _installed_modules_cache
|
return _installed_modules_cache
|
||||||
|
|
||||||
class LazyDate:
|
class LazyDate:
|
||||||
@ -416,8 +420,8 @@ class Options:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Options for %s>' % self.module_name
|
return '<Options for %s>' % self.module_name
|
||||||
|
|
||||||
def get_model_module(self):
|
# def get_model_module(self):
|
||||||
return get_module(self.app_label, self.module_name)
|
# return get_module(self.app_label, self.module_name)
|
||||||
|
|
||||||
def get_content_type_id(self):
|
def get_content_type_id(self):
|
||||||
"Returns the content-type ID for this object type."
|
"Returns the content-type ID for this object type."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user