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

How to create a Challenge from a function that's importing the Class

I'm not sure what I'm missing here to complete this challenge. I thought this would create a new Challenge, but I guess not. Any hints?

crud.py
from models import Challenge


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

2 Answers

Hi Chase!

You need to use the create method from the Challenge class.

This passes:

from models import Challenge

def create_challenge(name, language, steps = 1): # steps = 1 sets the default value
    Challenge.create(name=name, language=language, steps=steps)

I hope that helps.

Stay safe and happy coding!

Thank you! I guess I'm kinda confused because how would I know that there was a model called create in Challenge?

Hi Chase!

I actually got that information by Googling the challenge question:

Challenge Task 1 of 1
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.

And got the answer here:

https://teamtreehouse.com/community/create-a-function-named-createchallenge-that-takes-name-language-and-steps-arguments

Evidently, you weren't the only one experiencing this issue!?!

I hope that helps.

Stay safe and happy coding!