Hi there,
I am new at using Python 3.8 and django 3.2.6.
I have created a project called “CAI us” with the following application:
caius
— caius
— fiscalite
------ models.py
— institution
------ models.py
Being in “fiscalite.models”, i would like to import a class (a table) from “institution.models”. I wonder if it is possible and how.
I also wonder if should create my applications in the parent folder (in “caius/[apps]” instead of “caius/caius/[apps]”).
Thank you very much for your help
Hi people,
.id m’y question clear enough? ![:roll_eyes: :roll_eyes:](https://emoji.discourse-cdn.com/twitter/roll_eyes.png?v=10)
You could import whatever you want if is in the Python path.
Thank you for tout answer.
I thought, being in “caius/fiscalite/model.py”, writing :
“from institutions.models import Institution” would be great but it raise an error:
“NameError: ‘Institutions’ is not defined”.
How to fix this error please ?
What I understand is “institutions” directory is on the same level that “fiacalite” directory. I have to find a way how “fiscalite/models.py” can import models from “institutions/models”.
Your diagram in the first post shows the directory name as “institution”, not “institutions”. Verify that the directory name (and case) are correct.
Typically, your first (top-most) “caius” directory is going to be the base directory for your app. In that case, yes, you would import from “institution.models”.
If this is not your base directory, then you need to adjust your imports accordingly.