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

Sagar Thakkar
Sagar Thakkar
8,814 Points

whats wrong in this code @kennath love

i am not getting the whats wrong in my code

songs/models.py
from django.db import models


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.TextField(),
    length = models.IntegerField(default = 0)
    performer = models.ForeignKey(Performer)

    def __str__(self):
        return ("{} by {}".format(self.title, self.artist)
songs/views.py
from django.shortcuts import render

from .models import Song, Performer

def song_list(request):
    songs = Song.objects.all()
    return render(request, "songs/song_list.html", {'songs': song})

def song_detail(request, pk):
    song = get_object_or_404(Song, pk=pk)
    return render(request, "songs/song_detail.html", {'song': song})

def performer(request, song_pk, performer_pk):
    performer = get_object_or_404(performer, song_id = song_pk, pk=performer_pk)
    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>

    {% for song in performer.song_set.all %}
      {% if song.performer.pk == performer.pk: %}
        {{ song }}
      {% endif %}
    {% endfor %}

{% endblock %}

4 Answers

Taylor Quinn
Taylor Quinn
20,003 Points

Your missing a comma in your model after your length entry. I am not positive that this would throw anything off but if I had to guess it probably does. I would take a look at your migration/db and make sure that the performer and length fields were created. If they were not generate a new migration to add those fields to your table. Also as a side note when seeking help with a problem its good practice to include what error is being raised when you run your code, it helps to narrow down what to look at when trying to help you.

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

variable = 'name' name = '.format' name ='david' david = 'subject' .format () subject{}"

Sagar Thakkar
Sagar Thakkar
8,814 Points

i am not getting your point please explain in little more detail

Sagar Thakkar
Sagar Thakkar
8,814 Points

i found 1 mistake which was performer to performer_detail in views.py line 13

Sagar Thakkar
Sagar Thakkar
8,814 Points

hay can any one help me pllllllllzzzzzzzzz????