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 trialmichaelangelo owildeberry
18,173 Pointsmake a variable named sorted_challenges that is all of the Challenge records, ordered by the steps attribute on the mode
make a variable named sorted_challenges that is all of the Challenge records, ordered by the steps attribute on the model. The order should be ascending, which is the default direction. ... what more could I be missing from my code? please help =)
from models import Challenge
all_challenges = Challenge.select()
Challenge.create(language='Ruby', name='Booleans')
def top_student():
sorted_challenges = Challenge.select().order_by().get()
return sorted_challenges
3 Answers
William Li
Courses Plus Student 26,868 PointsHello, michaelangelo
Finally, make a variable named sorted_challenges that is all of the Challenge records, ordered by the steps attribute on the model.
Since this part of Challenge didn't ask you to define a function, you should not do that. So take this line of your code sorted_challenges = Challenge.select().order_by().get()
out of the function body and get rid of the function.
And there're some issues with this line
- You previously assigned
Challenge.select()
to all_challenges variable, so you should use that variable here instead of callingChallenge.select()
again. - Don't use
.get()
, you are supposed to pass an argument toorder_by()
so that it knows to how sort the query, what argument to pass in? The challenge tells you that
ordered by the steps attribute on the model
the final code should look like this
from models import Challenge
all_challenges = Challenge.select()
Challenge.create(language='Ruby', name='Booleans')
sorted_challenges = all_challenges.order_by(Challenge.steps)
Alexander Torres
4,486 PointsAnyone correct me if I am wrong. I believe William Li said to not use .get() method because in the task it specifically says "the order should be ascending by default." where TreeHouse wants us to create a variable to show the order instead of trying to "get" a specific data from the table. I hope I make sense.
michaelangelo owildeberry
18,173 Pointsoops =D now I understands
tomasvukasovic
24,022 Pointstomasvukasovic
24,022 PointsOne small tiny bit question, why shouldn't we use get ? It because its more pythonist not to use it or there is a specific reason?