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

Peewee Challenge: CRUD Problem (SOLVED)

Can someone help me? I can't find the error in here.

Thank you in advance! ~Alexander

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, language):
    results = Challenge.where(Challenge.name == name, Challenge.language == language)
    return results

1 Answer

Here is the code:

from models import Challenge


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

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

You need the select() before where(). The instruction also want you to see if the Challenge.name contains the name rather than them being equal. This can be done with contains(name). I had to read over the problem again because it is something that can be easily missed.

Also, if you're wondering why select() needs to come before where(), it's python's version of SQL where you the first line has to be SELECT (the FROM statement would be next to state the table, but for peewee this is accomplished by putting select() after Challenge which ultimately says we are selecting from Challenge) and then you would have WHERE after that.

Thank you! I totally forgot the select() part.

Thanks! :) :dizzy: