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

i have been working on this challenge for like 2 hours, is this challenge valid?

i have been working on this challenge for almost 2 hours because it lacks the information needed in the question prompt. i keep trying o fetch data from the errors i get. i can't proceed with the modules until i pass this yet i find it very hard since i've been stuck on the same point for too long. the last error i got was "i don't see Ruby Booleans Challenge" which i'm pretty sure is there!! so what shall i do in order to fix my code or to bypass the challenge to proceed with my tutorials? also i would advice you add more details to the prompt as it is not logical to keep fetching for your requirements through error messages.

from peewee import *
db = SqliteDatabase('challenges.db')
class Challenge(Model):
    name = CharField( max_length = 100 )
    language = CharField( max_length = 100 )
    steps = IntegerField()
    class Meta:
        database = db

challenges = [ {'name' : 'Booleans', 'language' : 'Ruby', 'steps' : 2}, {'name' : 'Booleans', 'language' : 'Ruby', 'steps' : 5}, ]
all_challenges = Challenge.select(Challenge.name, Challenge.language, Challenge.steps)
def challenge_add():
    for challenge in challenges:
        Challenge.create(name=challenge['name'], language=challenge['language'], steps=challenge['steps'])
def sort():
    return all_challenges.order_by(Challenge.steps.asc())
sorted_challenges = sort()
Myers Carpenter
Myers Carpenter
6,111 Points

It's important to remember the challenges build on each step. Usually the code you write in step 1 stays the same for the rest of the steps.

In your code rather than import the Challenge from models.py you've actually wrote your own version of that class. Was there a reason to do that?

1 Answer

Hi Ahmad, I think you might be over complicating this challenge. Below are the 4 lines of code needed to solve all 4 steps on this code challenge. let me know if there is something that you are unsure of, or not understanding.

from models import Challenge

all_challenges = Challenge.select()

Challenge.create(name='Booleans', language='Ruby')

sorted_challenges = all_challenges.order_by(Challenge.steps.asc())