Chaining Queries

One of the strengths of Django ORM is the ability to chain multiple queries together. This allows you to construct complex queries step by step. For example, to get recent posts that are not in the “Tech” category:

from .models import BlogPost
from datetime import date
queryset = BlogPost.objects.filter(pub_date__gt=date(2023, 1, 1)).exclude(category="Tech")

Last updated