Where i can learn about how oop is implemented in django?

Whenever i read code like " post.objects.all()" i understand post is a class that extends models.Model class. But i can't understand what is "objects" in "post.objects.all()". Please help me to understand how oop works in django in-depth.

Posted Apr 22, 2019, 5:59 AM UTC

16

A Model represents a single row in a table. A Manager represents the entire table. That's why the query methods exist there, e.g. "fetch all rows", "fetch the last 10 rows", etc.

1
yee_mon•

Django models are no ordinary Python classes. They behave in some very weird ways if you think about it. Thus, I wouldn't try to make sense of .objects as some OOP concept (although if you need to, it's a Manager instance), but rather as all the instances of the model it is attached to, with convenient methods to access a subset of them.

Almost any method call on .objects is going to return a QuerySet -- just like the methods on QuerySet.

1
NaveenCoderOP•

Thanks everyone for answering. I got the idea

1
haloweenek•

That’s the model queryset manager. Read the manual it’s there...

0