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

django TDD

cant get my code to pass please help

songs/models.py
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)
    performer = models.ForeignKey(Performer)
    length = models.IntegerField()

    def __str__(self):
        return '{} by {}'.format(self.title, self.artist)
songs/views.py
from django.shortcuts import get_object_or_404, get_list_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)
    performer.song_set.all()
    return render(request, 'songs/performer_detail.html', {'performer': performer})
songs/templates/songs/performer_detail.html
{% extends 'base.html' %}

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

{% block content %}
<h2>{{ performer }}</h2>
{% endblock %}
Nate Hawk
Nate Hawk
13,229 Points

Why is everyone using length in this test? I am very confused, the readme says that the Song model should have a duration and not a length. I don't see duration in people code.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Since, it's TDD, the test dictates the necessary code. In the test test_song_string (see kareoke/songs/tests.py) a new song is constructed using the keyword "length". Calling the field anything else in the model would raise an error.

Should the test and the README.TXT have agreed on the name to use? Probably, but since it's TDD and not SpecDD, the test wins.

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Your code doesn't pass for me in the Workspace. I get that a song title isn't showing up in the template. If you look at the test, it says the song title should be in the template and your template doesn't ever reference the song title.

Its not failing in the workspaces but in the treehouse challenge its saying bummer not all tests are passing!!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Are you seeing this in the console window?

treehouse:~/workspace$ cd karaoke/
treehouse:~/workspace/karaoke$ python manage.py test
Creating test database for alias 'default'...
.....
----------------------------------------------------------------------
Ran 5 tests in 0.088s

OK
Destroying test database for alias 'default'...
treehouse:~/workspace/karaoke$
Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

When you run the tests in the Workspace, what fails?

Its not failing in the workspaces but in the treehouse challenge its saying bummer not all tests are passing!!