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

Python First Queries

Don't know what database is meant and how to complete the task. Please Help. Thx

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Access to the database is built in to the inherited method select(). This is inherited from peewee.Model. The database is specified in theMetasubclass of the modelChallenge`.

For example, as seen in the Modeling video, The Student class

    class Student(Model):
        username = CharField(max_length=255, unique=True)
        points = IntegerField(dafault=0)

        class Meta:
            database = db

So Task 2 can be solved using:

# Challenge Task 1 of 4
# Import the `Challenge` class from `models.py`.

from models import Challenge

# Challenge Task 2 of 4
# Now, create a variable named `all_challenges`. It should select all of the available challenges from the database.

all_challenges = Challenge.select()