[Django]-Django TypeError: 'RelatedManager' object is not iterable

234👍

Try this:

block in group.block_set.all()

33👍

Use it like a Manager. If you want all the objects then call the all() method.

16👍

you have to use .all() with related name or childModel_set model name .

in views.py use :

for item in object.relatedname.all():
    do something ......

in html templates use:

 {% for item in object.relatedname.all %}
   do something ......
 {% endfor %}
👤K.A

2👍

If you are expiriencing this error in Django template try:

{% for block in group.block_set.all %}
{{ block }}
{% endfor %}

Leave a comment