Well, the error is self-descriptive.
What he says is that there is the name "department"- the prefix .apps
tells Python - the language - that in the directory where this file is - that possibly is in another "app" of Django, there is a folder apps
, and inside that folder he could find a directory with name departamentos
or a file called departamentos.py
. Not the case - if your Django project is structured in the way described in the documentation for Django, you have an "app" "departments" sister app "employee" a folder above.
Import will work if you import the "departments" package directly, once Django configures Pythonpath to find the apps installed in the project:
from departamento.models import Departamento
Unless mistaken, Django’s ORM is also smart enough to find the template from a string, with the name_da_app.template name_do_template - in this case, you don’t even need to import -just change your field statement to:
departamentos = models.ManyToManyField("departamentos.Departamento")
(Django’s ORM has this feature - the "saved mistake" is that I don’t remember if anything else has to be put in the string to address the other model correctly).