Andrew Godwin committed ebe91ac

Fix circular/reverse dependency issues with primary_key relation fields

Comments (0)

Files changed (1)

         # Now, make each model's data into a FakeModel
+        # We first make entries for each model that are just its name
+        # This allows us to have circular model dependency loops
+        model_names = []
         for name, data in self.models_source.items():
             # Make sure there's some kind of Meta
             if "Meta" not in data:
                 model_name = name
                 name = "%s.%s" % (app_name, model_name)
-            self.models[name.lower()] = self.make_model(app_name, model_name, data)
+            name = name.lower()
+            self.models[name] = name
+            model_names.append((name, app_name, model_name, data))
+        for name, app_name, model_name, data in model_names:
+            self.models[name] = self.make_model(app_name, model_name, data)
         # And perform the second run to iron out any circular/backwards depends.