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 trialThomas Mabika
5,067 Pointswhat is wrong with this code?????
Bummer! Try again
Copy and paste your models, views, and performer template from Workspaces into the correct files below.
from django.db import models
class Song(models.Models):
title = models.CharField(max_length=255)
artist = models.Charfield(max_length=255)
length = models.IntegerField()
performer = models.ForeignKey('Performer')
def __str__(self):
return self.title
class Performer(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
from django.shortcuts import get_object_or_404, render
from .models import Song, Performer
def song_list(request):
songs = Song.objects.all()
return render(request, 'songs/song_list.html', {'songs': songs})
def song_detail(request, pk):
song = get_object_or_404(Song, pk=pk)
return render(request, 'songs/song_detail.html', {'song': song})
def 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})
{% extends 'base.html' %}
{% block title %}{{ performer }}{% endblock %}
{% block content %}
<h2>{{ performer }}</h2>
{% for song in songs %}
{{ song }}
{% endfor %}
{% endblock %}
1 Answer
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsHey Thomas Mabika
I wont give you the answers but I will give you a few hints of where to look. (there are a few errors) I see.
songs/models.py
Your Song class has 3 small errors in it. 1 is related to what your str returns, make sure you read the README in the Workspace. The others two are typos, read each line and character carefully.
Let me know if that helps ;)
Thomas Mabika
5,067 Pointsstill can't get where I'm going wrong, did a few changes and still not passing, can you just give me the answers Chris?
Chris Howell
Python Web Development Techdegree Graduate 49,702 Pointsclass Song(models.Models): # problem on this line(is there a "Models" in models?)
title = models.CharField(max_length=255)
artist = models.Charfield(max_length=255) # problem on this line(look at character casing)
length = models.IntegerField()
performer = models.ForeignKey('Performer')
def __str__(self):
return self.title #problem on this line(should return more than title)
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsChristopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsHave you run python manage.py test in the workspace to see which test(s) is failing?