It is a follow up to this question and answer. My question now is, when I have a ModelMultipleChoiceField in my form how do I access all of the model fields of a passed queryset in template?
Currently my form is:
class CarChoicesForm(forms.Form):
def __init__(self, *args, **kwargs):
cars = kwargs.pop('cars', None)
super(CarChoicesForm, self).__init__(*args, **kwargs)
self.fields['cars']=forms.ModelMultipleChoiceField(queryset=cars,
widget=forms.CheckboxSelectMultiple)
Template:
<tbody>
{% for choice in form.cars %}
<tr>
<td>{{ choice.choice_label }}</td>
<td><span class="checkbox">{{ choice.tag }}</span></td>
</tr>
{% endfor %}
</tbody>
It only prints what Car.__str__()
provides, but I need other fields to achieve something like this. I tried {{ choice.choice_label.brand }}
, etc. with no success.