Guided Notes

QuerySets

Getting, filtering, excluding, ordering, and slicing data, field lookups, values, and following relationships.

What is a QuerySet?

Slide 1 / 5

A QuerySet is a collection of objects from the database, built with Model.objects:

Book.objects.all() — every book.

QuerySets are lazy: building one doesn't touch the database. The SQL runs only when you use the results — loop over them, print them, count them, or slice them. You can chain methods to refine a query step by step, and Django combines them into one SQL statement.

← Models & ORM