简体   繁体   中英

Django Models: Where is Model class?

On documentation it has been said that each model is a python subclass of models.Model class that is inside django folder followed by db folder . When i look inside my django folder i see a db folder which was expected and inside my db folder i see models folder which contains lot of files. But I was expecting a models.py package which contains Model class. So my doubt is from where does this models.Model class come from?

This might be not a top level question but I am hopeful someone here will certainly help.

Nope it's not magic it's django , it does exist if you go to the django's source code, you can see that the Model class exists , But in that way don't you had to import models in this way??:

from django.db.models.base import Model

Yes you can do it in that way, But django does it for you in the models/ __init__ file, so the only thing you have to do is:

from django.db import models

models refers to the models folder inside django.db but when you import it, it brings you all the things that are inse the models/____init__ .py file, I recommend you to read this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM