ManyRelatedManager is not iterable

Trying to do this:

Updated:

wishList = WishList.objects.get(pk=20) matches = [val for val in Store.attribute_answers.all() if val in wishList.attribute_answers] 

and get it ...

 'ManyRelatedManager' object is not iterable 

Both fields are diverse, so how can this be done?

+67
django
Feb 17 '13 at 11:48
source share
5 answers

Try

 matches = [val for val in Store.attribute_answers.all() if val in WishList.attribute_answers.all()] 
+86
Feb 17 '13 at 12:17
source share

sounds like you're looking for something like Store.attribute_answers.all()

+44
Feb 17 '13 at 12:16
source share

For all guys who find reading code in questions like TL; DR

Instead of query_set.many_to_many

You should use query_set.many_to_many.all()

+11
Jul 24 '18 at 14:55
source share

if you do it in a template

  {% for room in study.room_choice.all %} {{ room }} {% empty %} empty list! {% endfor %} 
+10
Jan 18 '19 at 10:58
source share

Here busines_type is Foreign_key in the profile model.

 pro = Profile.object.filter(user=myuser).first() business_type = pro.business_type.all() if business_type: b_type = '' for b in business_type: b_type += str(b.type)+' ' a = b_type 
0
Mar 14 '19 at 10:10
source share



All Articles