开发者

difference between models.Manager and models.Model

What is the difference between models.Manager and models.Model?

I would like to know more about models.Manager. Some references to tu开发者_如何转开发torials and practical examples would be helpful.


Managers

Models

In other words, everything. Models have a manager in the objects attribute by default.


You need to read the official Django documentation for both Models and Managers before going any further:

https://docs.djangoproject.com/en/1.6/topics/db/models/

https://docs.djangoproject.com/en/1.6/topics/db/managers/

... be sure to replace the 1.6 in each link with your current django version.

Manager objects contain one or more methods for querying the data that their Models represent. Each Model class is assigned 1 manager object by default (Model.objects), but the Model class is NOT limited to just 1 manager object - the default one can be overridden and/or additional custom-built Managers can be assigned to a specific Model class. It would probably be best to create a separate PY file to contain ALL the Managers for each specific app (name the file 'managers.py'), but storing them in 'models.py' would also do just fine.

And if none of this makes any sense, don't worry - just visit the djangoproject homepage and under 'Documentation' click on 'tutorial' ... work through this tutorial first and then you'll be good to go.

good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜