May 2018
Beginner to intermediate
526 pages
11h 57m
English
The Django object-relational mapping (ORM) is based on QuerySets. A QuerySet is a collection of objects from your database that can have several filters to limit the results. You already know how to retrieve a single object from the database using the get() method. We have accessed this method using Post.objects.get(). Each Django model has at least one manager, and the default manager is called objects. You get a QuerySet object using your model manager. To retrieve all objects from a table, you just use the all() method on the default objects manager, like this:
>>> all_posts = Post.objects.all()
This is how we create a QuerySet that returns all objects in the database. Note that this QuerySet has not been executed yet. ...
Read now
Unlock full access