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

Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

Create_challenge function

How do you create the name,language, and steps with the Challenge model?

crud.py
from models import Challenge



def create_challenge(name,language,steps=1):

2 Answers

Steven Parker
Steven Parker
231,248 Points

Using the technique demonstrated in the previous video, you can call the "create" method on the imported "Challenge", and pass it keyword arguments.

Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

I saw a post about this challenge and the student passed with setting the arguments to themselves (name=name) on the create() function, including the steps argument when it’s 1 by default.

Steven Parker
Steven Parker
231,248 Points

Exactly. An example of the "keyword arguments" I mentioned would be "name=name".

Matthew Smith
Matthew Smith
3,083 Points

The problem with this particular challenge is that it involves working with the Challenge class from models. The video prior to this is about the diary.py app that the instructor is writing. For many of these challenges using the Challenge class, we don't have visibility into what the challenge class contains. We can look at the documentation for the peewee library, but there is a level of abstraction between that and this challenge.

valeriuv
valeriuv
20,999 Points

I got stuck for awhile on this challenge too.

Basically, in the create method on the Challenge, you assign the parameters from the function to the model variables from the model we created in the previous challenge. It goes like this: Challenge.create(name=name, language=language, steps=steps)