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 Meet Peewee First Queries

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Challenge object is not iterable

I don't understand why I am getting this error. I have tried to follow the example in the video which was: student = Student.select().order_by(Student.points.desc()).get()

queries.py
from models import Challenge
all_challenges = Challenge.select()
Challenge.create(language = 'Ruby',name = 'Booleans')
sorted_challenges = all_challenges.order_by(Challenge.steps.asc()).get()
Elizabeth McInerney
Elizabeth McInerney
3,175 Points

I just figured this one out. I should not have ended that last line with .get(). The challenge was looking for all of them, not just one.

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Elizabeth.

I don't remember the particular video that you are referring too, but my idea is: Shouldn't you just do something like you did in task 1/4 and then simply order_by the steps?

I didn't understand (and remember) that final .get() so I had to look at peewee's docs for get (http://peewee.readthedocs.org/en/latest/peewee/api.html#Model.get) and also I reviewed the video. From minute 6.50 it explains that .get() is added to only retrieve the first record, which is not what we want here.

Does it make sense?

Vittorio

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Thanks Vittorio, see my comment after my question above. I figured out that I needed to remove get(). I thought adding a comment would prevent someone else from thinking about my original question. Perhaps there is a way to delete questions if you have solved the problem before someone else replies.

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

No problems Elizabeth,

just leave the forum question as it is as it may be helpful for someone else in future.

In general the forum marks a question as "closed" or "resolved" when the user who asked the question picks the best answer to it.

Have a nice day Vittorio

Elizabeth McInerney
Elizabeth McInerney
3,175 Points

Thanks, I did not realize that about "best answer".