[Django]-Are "Field" and "Fields" reserved words in Django or Python?

2đź‘Ť

âś…

Strictly speaking, “reserved word” is the wrong term here. Reserved words are properties of a programming language, and Django is not a language.

There is a class called Field in Django in the django.db.models.fields package, and another (similar but different) class with the same name in the django.forms.fields package.

However, these Field classes are so low level classes that it’s unlikely that you will ever need to import them, so they won’t interfere with your own Field class.

In any case, and as you can see, within Django itself the same class can exist in multiple packages with the same name. It’s fine, because the package name serves as a namespace, so you can always fully qualify a class by using its complete package name.

Another useful thing in Python is importing classes with a different name:

from django.db.models.fields import Field as DjangoField
help(DjangoField)

Similarly, importing packages with a different name:

from django.db.models import fields as djangofields
help(djangofields.Field)

This way you can always avoid collisions in class and package names.

👤janos

2đź‘Ť

little explanation with fun

Answer is Simply No,

Because Language only has the authority to own anything.Python is the owner of the house
The Django guy is paying rent to Python guy. So, How Django guy can reserve the objects of the house?

same logic is applied here too

👤Nava

Leave a comment