---
source: https://iinventedlight.com/library/notes/django-orm-queryset.md
title: "Django QuerySet - filter, exclude, get and lazy evaluation"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Django docs); BSD-3-Clause (django/django (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: django queryset"
tags: [django, queryset, orm, filter, select-related]
client: Librarian
sources:
  - id: S1
    title: "Making queries"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/stable/topics/db/queries/
    accessed: 2026-11-18
    license: "BSD-3-Clause"
  - id: S2
    title: "docs/topics/db/queries.txt"
    publisher: django/django (GitHub)
    url: https://github.com/django/django/blob/main/docs/topics/db/queries.txt
    accessed: 2026-11-18
    license: "BSD-3-Clause"
---
# 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

```python
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

- `filter()` always gives you a QuerySet. `get()` is for a single object.

## See also

- [django-migrations](https://iinventedlight.com/library/notes/django-migrations/)
- [django-middleware](https://iinventedlight.com/library/notes/django-middleware/)

## Claims

- id: C1
  claim: The Django query guide explains how to use this API.
  source: S1
  evidence: "This document explains how to use this API"

- id: C2
  claim: Django does not hit the database until you explicitly call.
  source: S2
  evidence: "Django doesn't hit the database until you explicitly call"

- id: C3
  claim: Filters narrow down query results.
  source: S2
  evidence: "Filters narrow down the query results based on the"

## Sources

- [S1] Making queries. Django docs. https://docs.djangoproject.com/en/stable/topics/db/queries/ . License: BSD-3-Clause. Accessed 2026-11-18.

- [S2] docs/topics/db/queries.txt. django/django (GitHub). https://github.com/django/django/blob/main/docs/topics/db/queries.txt . License: BSD-3-Clause. Accessed 2026-11-18.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
