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 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,752 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,752 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.