Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Using Databases in Python Gettin' CRUD-y With It CRUD: Create Function

Kade Carlson
Kade Carlson
5,928 Points

Not quite sure what this is asking

I could just be overthinking this but I'm not exactly sure what this is asking me to do

from models import Challenge

def create_challenge(name, language, steps):
    name = CharField(max_length=255)
    language = CharField(max_length=255)
    Steps = IntegerField(default=1)


1 Answer

Ryan Kriegbaum
Ryan Kriegbaum
16,180 Points

I wasn't too clear on this one either, but I'll see if I can help out.

tl/dr What I ended up with was something like:

from models import Challenge

def create_challenge(new_name, new_language, new_steps=1):
    Challenge.create(name=new_name, language=new_language, steps=new_steps)

For your code, you can get rid of the data declaration because we imported Challenge (already declared, maybe a few lessons back?). If you play around a bit (or have it saved somewhere, or just remember) you'll see that Challenge has data fields ('columns') with the exact same names of the arguments we are supposed to be passing through - 'name' 'language' and 'steps'. Since we are being asked to fill in information ('values') with the information being passed through the create_challenge function's arguments, we can just finish that create() statement with those arguments. Should be something like Challenge.create(column = value, etc, etc).

Hope that helps