Menu

Django ORM and QuerySets

Django ORM and QuerySets

QuerySets

A QuerySet is a collection of database queries that Django hasn't necessarily executed yet. This lazy evaluation is one of the ORM's most important characteristics — it lets you build up a query incrementally and only hit the database when you actually need the results.

Filtering and Ordering Data

Django's ORM field lookups use double-underscore syntax to express comparisons without writing raw SQL:

Model Relationships

Real applications have related data. Django's ORM handles three types of database relationships.

Output: