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 trial

Python Django Basics Test Time Django TDD

what is wrong with this code?????

Bummer! Try again

Copy and paste your models, views, and performer template from Workspaces into the correct files below.

songs/models.py
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
songs/views.py
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})
songs/templates/songs/performer_detail.html
{% extends 'base.html' %}

{% block title %}{{ performer }}{% endblock %}

{% block content %}
<h2>{{ performer }}</h2>
  {% for song in songs %}
   {{ song }}
  {% endfor %}
{% endblock %}

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hey 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 ;)

still 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points
class 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)