Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Build a Social Network with Flask Making Strong Users Flask and Peewee Review

Hanley Chan
Hanley Chan
27,771 Points

Help with quiz question regarding sorting based on published attribute.

I am having trouble with this quiz question:

In the following query, I want to change the sorting of my records. How would I sort them based on their published attribute so I get the oldest first?

Entry.select()._____(_____)

I tried "Entry.select().order_by(Entry.published.desc())", but it is not correct. What is the correct answer for this one?

Keith Whatling
Keith Whatling
17,696 Points

Yep same here. I tried the below and felt sure it should work?

Entry.select().order_by(Entry.published.asc())

2 Answers

Keith Whatling
Keith Whatling
17,696 Points

AH HA

Finally after 5 tries!

Ok so the thing we are all doing wrong it being too damn complex. Leave all reference to asc() and desc(), no need for plus and minus. Grr that was really frustrating.

Entry.select().order_by(Entry.published)

The PeeWee docs are missing the bit that tell you that there is a default to order_by, or the treehouse test needs a little tweak.

Hope this helps.

Anna Hull
Anna Hull
6,600 Points

I am working on this quiz right now as well - according to the PeeWee Docs this should work:

Entry.select().order_by(Entry.published.asc())

Or one of these:

Entry.select().order_by(+Entry.published)
Entry.select().order_by(-Entry.published.desc())

Kenneth Love, maybe you can help us out with this one!

This question was also answered here on Treehouse Forums.