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

Alex Trost
Alex Trost
6,270 Points

Confused on "Create a function named search_challenges"... can someone explain in plain english?

"Create a function named search_challenges that takes two arguments, name and language. Return all Challenges where the name field contains name argument and the language field is equal to the language argument. Use == for equality. You don't need boolean and or binary & for this, just put both conditions in your where()."

This lesson has continually felt like they're testing before they explain the item, or it's not super clear what is being requested. Can someone break this down in simpler english so that I have an idea of what I need to do? It's tough when info is being passed to me from imported modules that I don't have access to.

Thanks!

crud.py
from models import Challenge


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

1 Answer

Steven Parker
Steven Parker
231,248 Points

The task isn't asking you for anything you need to dig into the import for. The example shows a create operation performed on "Challenge", so you can expect that a select() would work on it also.

So if we break down the task:

  • Create a function named search_challenges :point_left: define a function
  • that takes two arguments, name and language :point_left: name the arguments
  • Return all Challenges :point_left: return the result of performing a select() on Challenge
  • where the name field contains name argument :point_left: add a .where() with a .contains expression for the name
  • and the language field is equal to the language argument :point_left: do an equality test
  • just put both conditions in your where(). :point_left: separate the two tests with a comma

There's a little bit more to accessing the fields, but assuming you recall how to handle that you should be able to get it now.

Alex Trost
Alex Trost
6,270 Points

Thank you yet again, Steven! You continue to come to my assistance. I got it now that you've broken it down. It was the 'where the name field contains the name argument' part that I think was really throwing me for a while.