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 Using Databases in Python Meet Peewee First Queries

make 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 =)

queries.py
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
PLUS
William Li
Courses Plus Student 26,868 Points

Hello, 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 calling Challenge.select() again.
  • Don't use .get(), you are supposed to pass an argument to order_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)

One 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?

Alexander Torres
Alexander Torres
4,486 Points

Tomas Vukasovic

Anyone 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.

oops =D now I understands