Learn how to efficiently utilize filters and queries in Django from basic to advanced with this guide to QuerySets and aggregations.

The object-relational mapper (ORM) in Django makes it easy for developers to be productive without prior working knowledge of databases and SQL. QuerySets represent a collection of objects from the database and can be constructed, filtered, sliced, or generally passed around without actually hitting the database. No database activity occurs until we do something to evaluate the QuerySet. In this guide, you will learn about how to perform these queries, both basic and advanced.

Throughout the guide, we will refer the django.contrib.auth.models.User model. You can insert multiple users into this model to test different QuerySets discussed in the following guide.

Moreover, we will be using the Django shell for running and testing the queries. You can start the Django shell with the following:

python manage.py shell

Basic Queries

Let’s start with some basic QuerySet operations.

#django #python

QuerySets and Aggregations in Django
2.30 GEEK