Django uses metaclasses to define models. There is a check to avoid defining the model twice, so when the class is created, if it is already defined, you get the version that was previously defined. See django.db.models.base.ModelBase :
from django.db.models.loading import get_model # Bail out early if we have already created this class. m = get_model(new_class._meta.app_label, name, False) if m is not None: return m
While the error classes are regular Python classes and there is no such caching, you get different versions, since the modules to which they belong are different. I think this happens because when you start Django runerver you end up in two ways of loading the same module from the path:
- Current directory
- Directory above current directory
This means that you can import fully qualified packages (including the name of the project) and it all works.
I try to never import the project name to avoid this problem.
source share