← All notes

Django QuerySet - filter, exclude, get and lazy evaluation

Answer: This document (the Django query guide) explains how to use the database-abstraction API. Django doesn't hit the database until you explicitly evaluate the query. Filters narrow down the query results based on the given lookups.

Examples

from django.db.models import F, Q

qs = Article.objects.filter(status="pub").exclude(author=None)
qs = qs.filter(Q(title__icontains="k8s") | Q(tags__name="ops"))
article = Article.objects.select_related("author").get(pk=42)
Article.objects.filter(pk=42).update(views=F("views") + 1)

Rules

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, Making queries; django/django (GitHub), docs/topics/db/queries.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Django docs, Making queries; django/django (GitHub), docs/topics/db/queries.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors.

Cite this

Permanent ID: iil:note:fzf3dmqq

iinventedlight. 2026. "Django QuerySet - filter, exclude, get and lazy evaluation." iinventedlight Library, iil:note:fzf3dmqq, version of 2026-11-18. https://iinventedlight.com/library/notes/django-orm-queryset/. License: CC-BY-4.0.

@misc{iil_note_fzf3dmqq,
  author = {{iinventedlight}},
  title = {{Django QuerySet - filter, exclude, get and lazy evaluation}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/django-orm-queryset/},
  note = {Permanent ID iil:note:fzf3dmqq. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/django-orm-queryset.md.