@@ -26,9 +26,6 @@ class AppCache(object):
26
26
# List of App instances
27
27
app_instances = [],
28
28
29
- # Keys of app_store are the model modules for each application.
30
- app_store = SortedDict (),
31
-
32
29
# Mapping of app_labels to a dictionary of model names to model code.
33
30
app_models = SortedDict (),
34
31
@@ -104,11 +101,9 @@ def load_app(self, app_name, can_postpone=False):
104
101
raise
105
102
106
103
self .nesting_level -= 1
107
- if models not in self .app_store :
108
- self .app_store [models ] = len (self .app_store )
109
- app = self .find_app (app_name .split ('.' )[- 1 ])
110
- if app :
111
- app .models_module = models
104
+ app = self .find_app (app_name .split ('.' )[- 1 ])
105
+ if app and models is not app .models_module :
106
+ app .models_module = models
112
107
return models
113
108
114
109
def find_app (self , app_label ):
@@ -133,9 +128,8 @@ def get_apps(self):
133
128
# Ensure the returned list is always in the same order (with new apps
134
129
# added at the end). This avoids unstable ordering on the admin app
135
130
# list page, for example.
136
- apps = [(v , k ) for k , v in self .app_store .items ()]
137
- apps .sort ()
138
- return [elt [1 ] for elt in apps ]
131
+ return [app .models_module for app in self .app_instances \
132
+ if app .models_module ]
139
133
140
134
def get_app (self , app_label , emptyOK = False ):
141
135
"""
@@ -184,15 +178,17 @@ def get_models(self, app_mod=None, include_auto_created=False, include_deferred=
184
178
pass
185
179
self ._populate ()
186
180
if app_mod :
187
- app_list = [self .app_models .get (app_mod .__name__ .split ('.' )[- 2 ], SortedDict ())]
181
+ app_label = app_mod .__name__ .split ('.' )[- 2 ]
182
+ app = self .find_app (app_label )
183
+ if app :
184
+ app_list = [app ]
188
185
else :
189
- #app_list = self.app_models.itervalues()
190
186
app_list = self .app_instances
191
187
model_list = []
192
188
for app in app_list :
193
189
models = app .models
194
190
model_list .extend (
195
- model for model in models #app.values()
191
+ model for model in models
196
192
if ((not model ._deferred or include_deferred )
197
193
and (not model ._meta .auto_created or include_auto_created ))
198
194
)
@@ -226,7 +222,7 @@ def register_models(self, app_label, *models):
226
222
self .app_instances .append (app )
227
223
for model in models :
228
224
# Store as 'name: model' pair in a dictionary
229
- # in the app_models dictionary
225
+ # in the models list of the App instance
230
226
model_name = model ._meta .object_name .lower ()
231
227
model_dict = self .app_models .setdefault (app_label , SortedDict ())
232
228
if model_name in model_dict :
0 commit comments