Found what I was looking for. In my form:
LINEITEM_CHOICES = [[x.id, x.descr] for x in LineItems.objects.all()]
class LineItemsForm(forms.Form):
food = forms.MultipleChoiceField(choices=LINEITEM_CHOICES,
widget=forms.CheckboxSelectMultiple(), required=False)
In my view:
{% for radio in lineItems.food %}
<div class="food_radios">
{{ radio }}
</div>
{% endfor %}
On Tuesday, January 5, 2016 at 10:39:31 PM UTC-6, Michael Molloy wrote:
>
> My model:
>
> class Product(models.Model):
> descr = models.CharField(max_length=100)
> cost = models.DecimalField(max_digits=5, decimal_places=2)
>
>
> For every row stored in the table represented by this model, in the
> template I would like to render the description and a checkbox so that the
> user can check it if he wants to buy it.
>
>
> Product 1 <input type=checkbox name=prodName1 value='Y'/>
> Product 2 <input type=checkbox name=prodName2 value='Y'/>
> Product 2 <input type=checkbox name=prodName3 value='Y'/>
>
>
>
> I can't figure out how to do that. I would be happy to manually render the
> form fields as checkboxes, but I don't know how to get the field id in the
> template.
>
>
> For example,
>
>
> {% for field in form %}
>
>
> <div id="{{ field.auto_id }}_container">
>
> <div>
> <label for="{{ field.auto_id }}">{{ field. }}:</label> <input id=
> "id_test1" name="test1" type="checkbox" />
> </div>
> <!--
> <div id="id_test1_errors">
>
> </div>
> -->
> </div>
>
>
> {{ field.help_text }}
> <div>
> {{ field.label_tag }} {{ field }}
> </div>
> {% endfor %}
>
>
> If this were java, I would write something like this in the jsp:
>
>
> <c:forEach var="row" items="${products.result.rows}">
> <input type=checkbox name='<c:out value=${row.id}/>' value='Y' /> <c:out
> value=${row.descr} />
>
> </c:forEach>
>
> But I don't know how to do that with Python and Django.
>
>
> And I may be coming at this totally wrong, so if that is the case, please
> feel free to tell me how I should be trying to do this.
>
>
> Thank you,
>
> --Michael
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/2bc7cf13-4ca7-4d63-93f6-212560ac91e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.