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 trialmarcolamoon
16,915 PointsNot for sure what i am doing wrong..HELP!
Copy and paste your models, views, and performer template from Workspaces into the correct files below.
from django.db import models
class Song(models.Model):
title = models.CharField(max_length=30)
artist = models.CharField(max_length=30)
performer = models.ForeignKey('Performer')
length = models.PositiveIntegerField(default=0)
def __str__(self):
return '{} by {}'.format(self.title, self.artist)
class Performer(models.Model):
name = models.CharField(max_length=30)
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 = Songs.objects.all()
return render(request, 'songs/song_list.html', {'songs': songs})
def song_detail(request, pk):
song = get_objects_or_404(Song, pk=pk)
return render(request, 'songs/song_detail.html', {'song': song})
def performer_detail(request, pk):
performer = get_objects_or_404(Performer, pk=pk)
songs = Song.objects.filter(performer=performer)
return render(request, 'songs/performer_detail.html', {'performer': performer})
def performer_detail(request,pk):
performer = get_object_or_404(Performer,pk=pk)
return render(request,'songs/performer_detail.html',{'performer':performer})
{% extends 'base.html' %}
{% block title %}{{ performer }}{% endblock %}
{% block content %}
<h2>{{ performer }}</h2>
{% for song in performer.song_set.all %}
{{ song.title }} by {{ song.artist }}
{% endfor %}
{% endblock %}
1 Answer
Jeff Muday
Treehouse Moderator 28,720 PointsYou are getting pretty close, don't let the syntax errors frustrate you -- in most python environments we have better syntax parsing than in the challenge environment.
Comments:
In models.py, the indentation of
def __str__(self):
needs to be fixed to make both of them part of the classIn views.py, you pluralized "Songs.objects.all()" it should be Song.objects.all() also... you pluralized the word "objects"` twice
songs = Songs.objects.all() # error, should be Song.objects.all()
song = get_objects_or_404(Song, pk=pk) # error should be get_object_or_404()
performer = get_objects_or_404(Performer, pk=pk) # error should be get_object_or_404()
- this may just be a typesetting thing, but the "def performer_detail(request,pk):" block is accidentally duplicated in the performer_detail.html. It should only be present in views.py