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

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,421 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())