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 trialCirrus Streamer
4,351 PointsAny ideas on silly error I am missing - cant get it to pass through the test.
Any ideas on silly error I am missing - cant get it to pass through the test.
from django.db import models
# Write your models here
class Performer(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Song(models.model):
title = models.CharField(max_length=255)
artist = models.CharField(max_length=255)
length = models.IntegerField()
performer = models.ForeignKey(Performer)
def __str__(self):
return '{} by {}'.format(self.title, self.artist)
from django.shortcuts import render, get_object_or_404
from .models import Song, Performer
def performer_detail(request, pk):
performer = get_object_or_404(Performer, pk=pk)
performer.song_set.all()
return render(request, 'songs/performer_detail.html', {'performer': performer})
def song_list(request):
songs = Song.objects.all()
return render(request, 'songs/song_list.html', {'songs': songs})
def song_detail(request, performer_pk, song_pk):
song = get_object_or_404(Song, performer_id = performer_pk, pk=song_pk)
return render(request, 'songs/song_detail.html', {'song': song})
{% extends 'base.html' %}
{% block title %}{{ performer }}{% endblock %}
{% block content %}
<h2>{{ performer }}</h2>
{% endblock %}
2 Answers
Jovan Dandridge
12,835 Pointsdef performer_detail(request, pk):
performer = get_object_or_404(Performer, pk=pk)
songs = Song.objects.filter(performer=performer)
return render(request, 'songs/performer_detail.html', {'performer': performer, 'songs': songs})