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

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

don't know where am wrong..its saying not all tests are passing

songs/models.py
from django.db import models

class Song(models.Model):
    title = models.CharField(max_length=255)
    artist = models.CharField(max_length=255)
    length = models.IntegerField(default=0)
    performer= models.TextField()


    def __str__(self):
        return self.title + self.artist


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 rnder(reqquest, 'song/song_list.html', {'songs': songs})


def song_detail(request):
    songs = 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.name }}{% endblock %}

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

1 Answer

Rogerio de Oliveira
PLUS
Rogerio de Oliveira
Courses Plus Student 21,319 Points

Hello Juliana.

I tested you code and found some issues I listed below:

In models.py you need to create a "ForeignKey" field in your Song class, like this: performer = models.ForeignKey("Performer") Continuing in the models.py, it's not an issue and it did pass, but dunder str method (str), in the Song class, is concatenating without any space, showing something like "<Song: title1artist1>".

In views.py i've found some typos. In the "song_list" function, just fix "rnder" to "render", "reqquest" to "request" and the template path from "song/song_list.html" to "songs/song_list.html". In the "song_detail" function, just include the "pk" parameter (def song_detail(request, pk):) and the variable "songs" needs to be "song" due to your code is getting a particular song.

After these fixes, the test passed.

bash-3.2$ python3 manage.py test Creating test database for alias 'default'...

.....

Ran 5 tests in 0.060s

OK Destroying test database for alias 'default'...

Hope I helped you.