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!

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

Andy Hughes
Andy Hughes
8,127 Points

First queries challenge task, written just to confuse me! :P

I had real problems with this, once again largely due to the confusing way the tasks were written and being asked to do things not explicitly done in the videos. So here's my tips and hints for the challenge.

Challenge Task 1 of 4

Import the Challenge class from models.py.

(hint: python already assumes you're using .py files)

Challenge Task 2 of 4

Now, create a variable named all_challenges. It should select all of the available challenges from the database.

(hint: one line of code. Remember to look for keywords that are used in the challenge description i.e. select. Then check where/how that was used in the video.)

Challenge Task 3 of 4

Next, create a new Challenge. The language should be "Ruby", the name should be "Booleans".

(hint: another single line of code. Again look for that keyword in the challenge description as it's telling you what to include after the "Challenge.xxx")(Go to 2.44 in the video where you'll see Kenneth demonstrate almost exactly what you need)

Challenge Task 4 of 4

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

(Hint: as before, one line of code. Keyword "ordered by". Look for that in the video and it will give you almost the exact format. Remember that we're being asked for ascending, which is the default for order_by so you shouldn't need to include anything extra for this to automatically be the case.)

Also remember that when you are being asked to do something with a database (i.e. .create .select .get), you need to first reference the model (i.e. themodel.select). Keep that in mind when they ask you to order the steps only.

Hope that helps, without doing it for you. :)