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: Search Function

I'm simplicitly stuck here.

.

crud.py
from models import Challenge

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

def search_challenges(name, languge):
    return Challenge.where(Challenge.name.contains(name)
nicole lumpkin
nicole lumpkin
Courses Plus Student 5,328 Points

Hey Sarah, I'd love to help but you're ahead of me in the materials :) I did however search the title of the challenge in the community and the second post I can across detailed an explanation as well as the solution. Perhaps you could work backwards and figure out where things went wrong. Search phrase: CRUD Search Function

Ken LaRose
seal-mask
.a{fill-rule:evenodd;}techdegree
Ken LaRose
Python Web Development Techdegree Student 21,982 Points

I am also stuck on this code challenge. I believe there are some syntax errors in your search_challenges function. But, then again, my function isn't working either.... check out the peewee documentation here: http://docs.peewee-orm.com/en/latest/peewee/querying.html#filtering-records

This is what I wrote:

def search_challenges(name, language):
    challenges =  Challenge.select().where(Challenge.name == name,
                                           Challenge.language == language)
    return challenges

if I figure it out, I'll post a follow-up comment

2 Answers

Ken LaRose
seal-mask
.a{fill-rule:evenodd;}techdegree
Ken LaRose
Python Web Development Techdegree Student 21,982 Points

okay... I figured it out. The query I posted in the comments above failed because it was searching for an exact match on name instead of using contains(). That's not your issue though. Basically you'll just want to insert the select() method between Challenge and where(), like Challenge.select().where(blah, blah). You're on the right track!