0👍
✅
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 %}
My code is based off of this post.
Thank you for your answers.
1👍
Ok, then you should design your model this way:
class Product(models.Model):
description = models.TextField()
cost = models.CharField(max_length=100)
# 'cost' should be a CharField because you would want to save currency name also e.g. €
users dont need a checkbox to buy it, I think, more appropriate way would be just an html button called “put into cart”, where users can put items into cart .. and then in cart page, you give users the chance to delete the selected items again. now you think further about next steps..
- Django : Urls with django-activity-streams
- Getting most recent by joining subquery in Django ORM
- Using custom permissions in view after log in django
- How to insert app-level constants into a django template
- Django HTTP 404 error when PUT or GET
0👍
in the model form you can specify in the meta class
class Meta:
widgets = {
'descr': CheckboxInput()
}
something like that anyway.
CheckboxInput is in django.forms.widgets I believe
- Updating a field in table A only by insert operation in table B
- Django-sorting Cannot reorder a query once a slice has been taken
- Google App Engine Apis
Source:stackexchange.com