Ticket #21682: 21682.diff
File 21682.diff, 3.7 KB (added by , 10 years ago) |
---|
-
django/db/models/base.py
diff --git a/django/db/models/base.py b/django/db/models/base.py index d906f2e..0428435 100644
a b class ModelBase(type): 86 86 meta = attr_meta 87 87 base_meta = getattr(new_class, '_meta', None) 88 88 89 app_label = None 90 91 # Look for an application configuration to attach the model to. 92 app_config = apps.get_containing_app_config(module) 93 94 if getattr(meta, 'app_label', None) is None: 95 if app_config is None: 96 if not abstract: 97 raise RuntimeError( 98 "Model class %s.%s doesn't declare an explicit " 99 "app_label and either isn't in an application in " 100 "INSTALLED_APPS or else was imported before its " 101 "application was loaded. " % (module, name)) 102 103 else: 104 app_label = app_config.label 89 app_label = getattr(meta, 'app_label', None) 90 if app_label is None: 91 # Look for an application configuration to attach the model to. 92 app_config = apps.get_containing_app_config(module) 93 # Only abstract models may be created outside of an application. 94 if app_config is None and not abstract: 95 raise RuntimeError( 96 "Model class %s.%s doesn't declare an explicit " 97 "app_label and either isn't in an application in " 98 "INSTALLED_APPS or else was imported before its " 99 "application was loaded. " % (module, name)) 100 else: 101 # Load for the application configuration with the given label. 102 app_config = apps.get_app_config(app_label) 105 103 106 new_class.add_to_class('_meta', Options(meta, app_ label))104 new_class.add_to_class('_meta', Options(meta, app_config)) 107 105 if not abstract: 108 106 new_class.add_to_class( 109 107 'DoesNotExist', -
django/db/models/options.py
diff --git a/django/db/models/options.py b/django/db/models/options.py index 83f1eb0..dc1016e 100644
a b class Options(object): 87 87 'local_concrete_fields', '_forward_fields_map') 88 88 REVERSE_PROPERTIES = ('related_objects', 'fields_map', '_relation_tree') 89 89 90 def __init__(self, meta, app_label=None): 90 def __init__(self, meta, app_config=None): 91 self.meta = meta 92 self.app_config = app_config 93 94 self.installed = app_config is not None 95 self.app_label = app_config.label if self.installed else None 96 91 97 self._get_fields_cache = {} 92 98 self.proxied_children = [] 93 99 self.local_fields = [] … … class Options(object): 104 110 self.default_permissions = ('add', 'change', 'delete') 105 111 self.permissions = [] 106 112 self.object_name = None 107 self.app_label = app_label108 113 self.get_latest_by = None 109 114 self.order_with_respect_to = None 110 115 self.db_tablespace = settings.DEFAULT_TABLESPACE 111 self.meta = meta112 116 self.pk = None 113 117 self.has_auto_field = False 114 118 self.auto_field = None … … class Options(object): 170 174 return link, model, direct, m2m 171 175 172 176 @property 173 def app_config(self):174 # Don't go through get_app_config to avoid triggering imports.175 return self.apps.app_configs.get(self.app_label)176 177 @property178 def installed(self):179 return self.app_config is not None180 181 @property182 177 def abstract_managers(self): 183 178 return [ 184 179 (counter, instance.name, instance) for counter, instance, abstract