[Answered ]-Django views many-to-many relationship field problem

1👍

recipe.id is the id of the through model RecipeMealPlan, and not Recipe, so instead of recipe.id, you need to use recipe.recipe.id.

Also for sanity’s sake, you could use something like recipemealplan instead of recipe as the variable name, so:

    {% for recipemealplan in mealplan.recipemealplan_set.all %}
        <li>{{ recipemealplan.get_meal_display}}: <a href="/recipe/{{ recipemealplan.recipe.id }}/">{{ recipemealplan }}</a></li>
    {% endfor %}

Leave a comment