Commits

Anonymous committed ccc8c6a

added dummy App class and track instances

Comments (0)

Files changed (3)

django/core/apps.py

+class App(object):
+    def __init__(self, name, models):
+        # fully qualified name (e.g. 'django.contrib.auth')
+        self.name = name
+        self.label = name.split('.')[-1]
+        self.models = models
+
+    def __repr__(self):
+        return '<App: %s>' % self.name

django/db/models/loading.py

 from django.utils.datastructures import SortedDict
 from django.utils.importlib import import_module
 from django.utils.module_loading import module_has_submodule
+from django.core.apps import App
 
 import imp
 import sys
     # Use the Borg pattern to share state between all instances. Details at
     # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531.
     __shared_state = dict(
+        # List of App instances
+        app_instances = [],
+
         # Keys of app_store are the model modules for each application.
         app_store = SortedDict(),
 
         self.nesting_level -= 1
         if models not in self.app_store:
             self.app_store[models] = len(self.app_store)
+            self.app_instances.append(App(app_name, models))
         return models
 
     def app_cache_ready(self):

tests/appcachetests.py

         cache.register_models('foo', *(FlatPage, Site,))
         self.assertFalse(cache.app_cache_ready())
         rv = cache.get_models()
+        # we have 4 models since the above import will trigger the
+        # ModelBase.__new__, which will call the register_models function
         self.assertEqual(len(rv), 4)
         self.assertEqual(rv[0], Site)
         self.assertEqual(rv[1], FlatPage)