Anonymous avatar Anonymous committed 2ea4a5a

Make a) stubs freeze with models they depend on for their PK and b) cross-app model references for those work - #121.

Comments (0)

Files changed (3)


         depends.update(field_dependencies(field, last_models))
     return depends
+def stub_model_dependencies(model, last_models=None):
+    """
+    Returns a set of models this one depends on to be defined as a stub model
+    (i.e. deps of the PK).
+    """
+    return field_dependencies(, last_models)
 def field_dependencies(field, last_models=None):
     depends = {}
     if isinstance(field, (models.OneToOneField, models.ForeignKey, models.ManyToManyField)):
-        if last_models:
-            depends[] = last_models
-        else:
-            depends[] = None
+        depends[] = last_models
+        depends.update(stub_model_dependencies(, last_models))
     return depends


             fields[fieldname] = inherited_fields[fieldname]
         # Is it a _ptr?
         elif fieldname.endswith("_ptr"):
-            fields[fieldname] = ("models.OneToOneField", [], {})
+            fields[fieldname] = ("models.OneToOneField", ["orm['%s.%s']" % (,], {})
         # Try a default for 'id'.
         elif fieldname == "id":
             fields[fieldname] = ("models.AutoField", [], {"primary_key": "True"})
             if name.split(".")[0] == app
+        # Ourselves as orm, to allow non-fail cross-app referencing
+        fake_locals['orm'] = self
         # And a fake _ function
         fake_locals['_'] = lambda x: x
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.