listado de objetos de ManyToManyField
Estoy tratando de imprimir una lista de todas las Conferencias y para cada conferencia, imprimir sus 3 Oradores.
En mi plantilla tengo:
{% if conferences %}
<ul>
{% for conference in conferences %}
<li>{{ conference.date }}</li>
{% for speakers in conference.speakers %}
<li>{{ conference.speakers }}</li>
{% endfor %}
{% endfor %}
</ul>
{% else %}
<p>No Conferences</p>
{% endif %}
En mi views.py archivo que tengo:
from django.shortcuts import render_to_response
from youthconf.conference.models import Conference
def manageconf(request):
conferences = Conference.objects.all().order_by('-date')[:5]
return render_to_response('conference/manageconf.html', {'conferences': conferences})
Hay un modelo llamado conferencia. que tiene una clase llamada Conferencias con un ManyToManyField nombrado oradores
Obtengo el error:
Caught an exception while rendering: 'ManyRelatedManager' object is not iterable
Con esta línea: {% for speakers in conference.speakers %}
47
Author: NaviRamyle, 2010-05-03
2 answers
Necesita llamar a all
en el campo muchos a muchos para obtener un objeto iterable. Además, la siguiente línea debe contener el orador en lugar de conference.speakers
.
{% for speaker in conference.speakers.all %}
<li>{{ speaker }}</li>
{% endfor %}
87
Author: interjay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-03 16:48:46
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-05-03 16:48:46
Similar dentro de pythoncode esto sería:
for speaker in conferenece.speakers.all():
print speaker.FIELDNAME
14
Author: Rickard Zachrisson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-28 10:37:17
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-28 10:37:17