Commits

Andrew Godwin committed 516b011

Don't add/remove models with managed=False (#312)

Comments (0)

Files changed (2)

south/creator/changes.py

         # See if anything's vanished
         for key in self.old_defs:
             if key not in self.new_defs:
-                yield ("DeleteModel", {
-                    "model": self.old_orm[key], 
-                    "model_def": self.split_model_def(self.old_orm[key], self.old_defs[key])[0],
-                })
+                # We shouldn't delete it if it was managed=False
+                if self.old_defs[key].get("Meta", {}).get("managed", "True") != "False":
+                    # Alright, delete it.
+                    yield ("DeleteModel", {
+                        "model": self.old_orm[key], 
+                        "model_def": self.split_model_def(self.old_orm[key], self.old_defs[key])[0],
+                    })
+                # We always add it in here so we ignore it later
                 deleted_models.add(key)
         
         # Or appeared
         for key in self.new_defs:
             if key not in self.old_defs:
-                yield ("AddModel", {
-                    "model": self.current_model_from_key(key), 
-                    "model_def": self.split_model_def(self.current_model_from_key(key), self.new_defs[key])[0],
-                })
+                # We shouldn't add it if it's managed=False
+                if self.new_defs[key].get("Meta", {}).get("managed", "True") != "False":
+                    yield ("AddModel", {
+                        "model": self.current_model_from_key(key), 
+                        "model_def": self.split_model_def(self.current_model_from_key(key), self.new_defs[key])[0],
+                    })
         
         # Now, for every model that's stayed the same, check its fields.
         for key in self.old_defs:

south/creator/freezer.py

         fields[name] = remove_useless_attributes(field)
     # See if there's a Meta
     fields['Meta'] = remove_useless_meta(modelsinspector.get_model_meta(model))
-    # Add in our own special item to track the object name
-    fields['Meta']['object_name'] = model._meta.object_name
+    # Add in our own special items to track the object name and managed
+    fields['Meta']['object_name'] = repr(model._meta.object_name)
+    fields['Meta']['managed'] = repr(model._meta.managed)
     return fields
 
 ### Dependency resolvers
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 ProjectModifiedEvent.java.
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.