Skip to content

Instantly share code, notes, and snippets.

@jarcoal
Created October 9, 2012 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarcoal/3855957 to your computer and use it in GitHub Desktop.
Save jarcoal/3855957 to your computer and use it in GitHub Desktop.
prefetch related post
<ul>
{% for product in products %}
<li>
<h4>{{ product.name }}</h4>
<ul>
{% for feature in product.feature_set.all %}
<li>{{ feature.name }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Product.objects.all().prefetch_related('feature_set')
SELECT
"products_feature"."id",
"products_feature"."product_id",
"products_feature"."name"
FROM
"products_feature"
WHERE
"products_feature"."product_id" IN (1, 2, 3, 4, 5)
print Product.objects.all().query
SELECT
"products_product"."id",
"products_product"."name",
"products_product"."description"
FROM
"products_product"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment