As noted earlier, Python is not Java. In particular, nothing is said in Python that the class should live in a file with the same name as the class.
As San4ez points out, the Model
class lives in django.db.models.base
and is imported into the __init__.py
file in this directory, so that it can be referenced directly as models.Model
. This is not some kind of magic, just normal idiomatic Python.
However, as soon as you look into the code for the class itself, you will find that in fact it consists of quite a lot of Python magic, especially around metaclasses. But that is another question.
source share