magic-removal: Changed 'app_package' variable name in ModelBase.__new__ and made slight sys.modules optimization

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2026 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-17 05:21:23 +00:00
parent 8816af6714
commit c7fc2bfb68
1 changed files with 3 additions and 3 deletions

View File

@ -32,11 +32,11 @@ class ModelBase(type):
new_class.add_to_class('_meta', Options(attrs.pop('Meta', None))) new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {})) new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
app_package = sys.modules.get(new_class.__module__) model_module = sys.modules[new_class.__module__]
# Figure out the app_label by looking one level up. # Figure out the app_label by looking one level up.
# For 'django.contrib.sites.models', this would be 'sites'. # For 'django.contrib.sites.models', this would be 'sites'.
app_label = app_package.__name__.split('.')[-2] app_label = model_module.__name__.split('.')[-2]
# Cache the app label. # Cache the app label.
new_class._meta.app_label = app_label new_class._meta.app_label = app_label
@ -48,7 +48,7 @@ class ModelBase(type):
new_class._prepare() new_class._prepare()
# Populate the _MODELS member on the module the class is in. # Populate the _MODELS member on the module the class is in.
app_package.__dict__.setdefault('_MODELS', []).append(new_class) model_module.__dict__.setdefault('_MODELS', []).append(new_class)
return new_class return new_class
def cmp_cls(x, y): def cmp_cls(x, y):