Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Optimizes Django ORM querysets by fixing N+1 queries, over-fetching, and misused select_related, prefetch_related, only, or defer.
82% 86%+5 ptsof test cases passed
Passed 19 of 22 test cases with the skill, and 18 of 22 without it.
3 of 3 safety checks passed
Not used yet
select_related() For Single-Valued Joinsorders = (
Order.objects
.select_related("account", "billing_address")
.filter(status="open")
)
Use when each row points to one related row. This joins related tables into the main query.
Good fit:
ForeignKeyOneToOneFieldorder.account.nameprefetch_related() For Many-Valued Relationsfrom django.db.models import Prefetch
orders = (
Order.objects
.filter(status="open")
.prefetch_related(
Prefetch(
"line_items",
queryset=LineItem.objects.select_related("product").order_by("position"),
)
)
)
Use when each parent has many children. Django issues a second query and joins results in Python.
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.