Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ManyRelatedManager not Iterable. Think I'm trying to pull my objects out incorrectly

I'm just trying to pull out each individual event from a list of events and perform an action on them. The code I currently have in my view is:

    user = request.user.get_profile()     followed = user.eventList     eL = [getEvent.getEvent(e_id) for e_id in followed] 

First, I'm grabbing the currently logged in user, then looking at his eventList, then iterating over it. I get the above error. Think I may be missing some line?

like image 512
Xonal Avatar asked Jul 18 '13 19:07

Xonal


1 Answers

Assuming from the error that eventList is a many-to-many field, you need to use .all() to get the related objects. A many-to-many field is a manager, so you can use it to construct querysets that return the actual objects.

user = request.user.get_profile() eL = user.eventList.all() 
like image 57
Peter DeGlopper Avatar answered Oct 22 '22 13:10

Peter DeGlopper