I am trying to display a ManyToManyField in my template:
class GvtCompo(models.Model):
startDate=models.DateField(max_length=10, blank=False, null=False)
endDate=models.DateField(max_length=10, blank=False, null=False)
gvtCompo= models.CharField(max_length=1000, blank=False, null=False)
class Act(models.Model):
gvtCompo= models.ManyToManyField(GvtCompo)
In my view, I can display the object, no problem:
for gvtCompo in act.gvtCompo.all():
print gvtCompo.gvtCompo
In my template, I have a list of "GvtCompo Object" with this code (not nice):
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field }}
</div>
{% endfor %}
I have tried to make it nicer, but the following code just not work (nothing appears):
{% for field in form %}
{% if field.name == "gvtCompo" %}
{% for gvtCompo in field.gvtCompo.all %}
{{ gvtCompo.gvtCompo }}
{% endfor %}
{% endif %}
{% endfor %}
What's wrong?
*Edit: *
If I don't use the form but an instance of the model (act) passed to render_to_response it displays the ManyToManyField values
{% for gvtCompo in field.gvtCompo.all %}
changed to
{% for gvtCompo in act.gvtCompo.all %}
However there is not form field anymore, so it can't be modified, validated and saved!