Reputation: 77
In django documentation, it say that we can retrieve data entry as below
entry = Entry.objects.get(pk=1)
Entry is a model class in models.py
. I tried to find the declaration of objects, but I can't find its declaration in manager.py
, just know it is a instance of Manager. So, where is the declaration of objects? Does it represent a set of Entry instances?
Upvotes: 1
Views: 219
Reputation: 599490
It's defined in ModelBase, which is the metaclass for model classes. See https://github.com/django/django/blob/master/django/db/models/base.py#L360
Upvotes: 0
Reputation: 506
When you define model, you extend Model class from django.db.models module. It will provide default model manager in objects property.
If you want to define custom model manager, you can do it by subclassing django.db.models.Manager class. Look at the docs how to do that: https://docs.djangoproject.com/en/1.11/topics/db/managers/
Add methods to custom model managers to if you want to manipulate with the collection of data. If you manipulate with single row, add method to your model.
Upvotes: 1