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 trialNgqabutho Moyo
2,538 PointsHow do I use the 'where' clause?
How do I design my query if 'Challenge' has no attribute 'where' (i.e. Challenge.where() is giving a syntax error)
from models import Challenge
def create_challenge(name, language, steps=1):
Challenge.create(name=name,
language=language,
steps=steps)
def search_challenges(name, language):
search = Challenge.select()
return search where(name==name, language==language)
1 Answer
Megan Amendola
Treehouse TeacherAt about 6:54 in the video before is where he talks about .where()
.
.where()
can either attached on to the end of Challenge.select().where(logic here)
or since you hade it a variable, you can use the variable search.where(logic here)
.
Here are some examples from the documentation as well: http://docs.peewee-orm.com/en/latest/peewee/querying.html#filtering-records
Ngqabutho Moyo
2,538 PointsNgqabutho Moyo
2,538 PointsI've corrected my query (I used 'return Challenge.select().where(Challenge.name==name, Challenge.language==language)') but the error states that the line did not return the correct number of records
Megan Amendola
Treehouse TeacherMegan Amendola
Treehouse TeacherThe challenge is asking for where the name field contains name argument. Right now you are checking for when the field is equal
==
to the name argument. Call.contains(name)
onChallenge.name
to check if it contains the name argument instead.