'RelatedManager' object is not iterable Django
Solution 1:
Call all()
to retrieve the elements from the manager.
{% for area in world_areas.all %}
Solution 2:
In general, it is better practice to use a values
or values_list
to pass data from a queryset to a template.
world_areas = Areas.objects.select_related().all().values_list('name', 'order_in_sidebar_network', ...)
Check out the Django docs for info on how to use the values
function if you haven't used it before.
Solution 3:
I run into this issue by a reckless mistake:
for physicalserver in task.physicalservers:
physicalserver.relieve_task()
The task.physicalservers
is RelatedManager
object, in my case I should get the task's physicalservers, there should add .all()
.
for physicalserver in task.physicalservers.all():