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 trialDevin Scheu
66,191 PointsPeeWee 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:
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
40,533 PointsYou 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
66,191 PointsDevin Scheu
66,191 PointsSo what would this look like in code?
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsFrom 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.
Devin Scheu
66,191 PointsDevin Scheu
66,191 PointsThanks Dan!