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 Gettin' CRUD-y With It CRUD: Create Function

Devin Scheu
Devin Scheu
66,191 Points

PeeWee Python Help

Question: Create a function named create_challenge() that takes name, language, and steps arguments. Steps should be optional, so give it a default value of 1. Create a Challenge from the arguments. create_challenge should not return anything.

Code:

crud.py
from peewee import *
from models import Challenge
def create_challenge(name, language, steps):
    name = CharField(max_length=100)
    language = CharField(max_length=100)
    steps = IntegerField(default=1)

1 Answer

Dan Johnson
Dan Johnson
40,533 Points

You don't need to define the model here, just create it using the Challenge model that is being imported. Since Challenge extends Model, you can call the create method on it.

Devin Scheu
Devin Scheu
66,191 Points

So what would this look like in code?

Dan Johnson
Dan Johnson
40,533 Points

From the peewee docs: http://peewee.readthedocs.org/en/latest/peewee/api.html#Model.create

Note that you won't need to capture the return for this challenge.