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 trialClayton Perszyk
Treehouse Moderator 48,850 Pointsproblem with search_challenges (receiving AttributeError)
I keep receiving the error: AttributeError: 'NoneType' object has no attribute 'count'... I've researched the error message to no avail. I've also looked at the documentation for the select() and where() methods, and feel like i'm calling them correctly. Thanks in advance for any help.
my 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):
challenges = Challenge.select()
challenges.where(Challenge.name.contains(name) & Challenge.language == language)
2 Answers
Kenneth Love
Treehouse Guest TeacherYou're not returning anything.
james white
78,399 PointsYes, the word 'return' is needed:
from models import Challenge
def create_challenge(name, language, steps=1):
Challenge.create(name=name,
language=language,
steps=steps)
def search_challenges(name, language):
return Challenge.select().where(
Challenge.name.contains(name),
Challenge.language==language
)
Of course, this didn't help me, because by the time I found this thread I had already moved on to the next challenge:
http://teamtreehouse.com/library/using-databases-in-python/gettin-crudy-with-it/crud-delete-function
Challenge Task 1 of 1
Create a function named delete_challenge that takes a Challenge as an argument. Delete the specified Challenge. Your function shouldn't return anything.
Watch the video over and over again:
http://teamtreehouse.com/library/using-databases-in-python/gettin-crudy-with-it/delete-an-entry
..at about time index 2:43 I found (and re-typed since there is no way to OCR text from the videos):
def delete_entry(entry):
entry.delete_instance()
..which I eventually 'translated' to:
def delete_challenge(Challenge):
Challenge.delete_instance()
Note: I wish this challenge wasn't so new...couldn't find many threads on it..
Kenneth Love
Treehouse Guest TeacherYou probably want to lowercase Challenge
in your delete_challenge
function so you don't confuse it with the class.
Clayton Perszyk
Treehouse Moderator 48,850 PointsClayton Perszyk
Treehouse Moderator 48,850 PointsProblem solved! Thanks, Kenneth.