[Fixed]-Query Django Object Lists of ForeignKey

1👍

Instead of querying Product in your tag, return

return {
    'menu_sections': MenuSection.objects.all()
}

Then, in your template,

{% for menu_section in menu_sections %}
    {{ menu_section.name }}
    {% for product in menu_section.product_set.all %}
        {{ product.name }}
    {% endfor %}
{% endfor %}
👤SMX

Leave a comment