Andrew Godwin committed e7a3bac

Apply new fix for 1.6 initial data loading. Thanks to tveastman

Comments (1)

Files changed (1)


 from import call_command
 from import loaddata
 from django.db import models
+from django import VERSION as DJANGO_VERSION
 import south.db
 from south import exceptions
         # Load initial data, if we ended up at target
         if self.verbosity:
             print(" - Loading initial data for %s." % target.app_label())
+        if DJANGO_VERSION < (1, 6):
+            self.pre_1_6(target, db)
+        else:
+            self.post_1_6(target, db)
+    def pre_1_6(self, target, db):
         # Override Django's get_apps call temporarily to only load from the
         # current app
         old_get_apps = models.get_apps
             models.get_apps = old_get_apps
             loaddata.get_apps = old_get_apps
+    def post_1_6(self, target, db):
+        import django.db.models.loading
+        ## build a new 'AppCache' object with just the app we care about.
+        old_cache = django.db.models.loading.cache
+        new_cache = django.db.models.loading.AppCache()
+        new_cache.get_apps = lambda: [new_cache.get_app(target.app_label())]
+        ## monkeypatch
+        django.db.models.loading.cache = new_cache
+        try:
+            call_command('loaddata', 'initial_data', verbosity=self.verbosity, database=db)
+        finally:
+            ## unmonkeypatch
+            django.db.models.loading.cache = old_cache
     def migrate_many(self, target, migrations, database):
         migrator = self._migrator
         result = migrator.__class__.migrate_many(migrator, target, migrations, database)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.