python - ImportError: Model A references Model B, Model B references Model A -


I think this is more dragon questions than Django.

But basically I am doing a model: A:

 Import ModelB from myproject.modelb.models  

And on Model B:

Import Model A Model from myproject.modela

Result:

Name of Can not import ModelA

Am I refusing to do anything? Thank you

A python module is imported from a top to bottom in a new name space. When the module has stopped evaluating A.py until an import module B, module B loads. When module B then imports module A, then it receives partial initial name of module A. - In your case, there is a lack of ModelA class because myproject.modelb .models occurs before the definition of that class.

In Django, you can correct it by referencing a model by the name of class object instead. Therefore, instead of saying

  to your project, import Model A Class ModelB: a = model You will use (without import):  
  class ModelB: a = model Ferrinki ('ModelA')  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -