2

I've looked into the source code for some django model fields, in this case DateTimeField. In the tutorial for Django, we are taught to create a DateTimeField like this:

from django.db import models

field = models.DateTimeField()

But looking in the source code, the file where DateTimeField is defined is django/db/models/fields. So, intuitively, if I were to import the field, I would write from django.db.models.fields import DateTimeField.

Do you see the difference? In the tutorial, they import it from django/db/models, while it looks like from the location of the source code that it actually resides in django/db/models/fields. Why doesn't the tutorial way of importing DateTimeField crash?

Sahand
  • 7,038
  • 19
  • 61
  • 121

1 Answers1

3

The fields are imported in django/db/models/__init__.py

Take a look at the source code.

Possibly relevant: What is init.py for?

rubayeet
  • 8,974
  • 8
  • 44
  • 54