Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEmmanuel Jimenez
21,666 Points{% for step in course.step_set.all %} not working
I have this code in the course_detail.html
{% extends "layouts.html" %}
{% block title %}
{{course.title}}
{% endblock title %}
{% block content %}
<article>
<h2>{{course.title}}</h2>
<section>
{% for step in course.step_set.all %}
<h3>{{step.title}}</h3>
{{step.description}}
{% endfor %}
</section>
</article>
{% endblock content %}
And in the models.py I have the ForeignKey en the course variable inside the Step class
from django.db import models
# Create your models here.
class Course(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=255)
description = models.TextField()
def __str__(self):
return self.title
class Step(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
order = models.IntegerField(default=0)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
def __str__(self):
return self.title
When I run the server and look for a specific course, I cant see the step title and the step description and I dont know what I'm doing wrong. Can anyone help me here?
1 Answer
Emmanuel Jimenez
21,666 PointsWow... I cant believe it. I didnt have a step on the course that I was displaing. O my god.