Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django Basics Django Templates Add a Detail View

Stuck with ManyToMany relationship

Hello I try to make the detail view with ManyToMany relationship

My urls: path('detail/<int:question_id>', views.DetailView, name = 'detail'), My models: from django.db import models class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField() def get_detail(question_id): return Question.objects.get(pk=question_id)

class Choice(models.Model): question = models.ManyToManyField(Question) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0)

My views:

def DetailView(request, question_id): q = Question.get_detail(question_id) choices = Choice.objects.filter(question__pk = q.id)
context = {"qs":q, "choices":choices} return render(request, "detail_question.html", context)

my template:

{% extends "base.html" %} {% block content123 %} {% if qs %} <h1>{{ qs.question_text }}</h1> <form action=""> <ul> {% for choice in choices %} <li><input type="radio" value="{{ qs.id }}" name="choice">{{ choice.choice_text }}<li> {% endfor %} </ul> <p><input type="submit" name="submit"</p> </form> {% endif %}

{% endblock %}

However after make mirgations and runserver, the page render only the Question, it does not render any choices