checkbox

How do I get multiple values from checkboxes in Django

How do I get multiple values from checkboxes in Django Question: I want to get values of a multiple select check box using request.POST[‘xzy’] as a list. Here is my model and template code. My Model class Recommend(models.Model): user=models.ForeignKey(User) book=models.ForeignKey(BookModel) friends=models.ManyToManyField(User, related_name=”recommended”) My Template {% for friend in friends %} <input type=”checkbox” name=”recommendations” id=”option{{friend.id}}” value={{friend.username}} …

Total answers: 2

Django Multiple Choice Field / Checkbox Select Multiple

Django Multiple Choice Field / Checkbox Select Multiple Question: I have a Django application and want to display multiple choice checkboxes in a user’s profile. They will then be able to select multiple items. This is a simplified version of my models.py: from profiles.choices import SAMPLE_CHOICES class Profile(models.Model): user = models.ForeignKey(User, unique=True, verbose_name_(‘user’)) choice_field = …

Total answers: 7

How do I create a Django form that displays a checkbox label to the right of the checkbox?

How do I create a Django form that displays a checkbox label to the right of the checkbox? Question: When I define a Django form class similar to this: def class MyForm(forms.Form): check = forms.BooleanField(required=True, label=”Check this”) It expands to HTML that looks like this: <form action=”.” id=”form” method=POST> <p><label for=”check”>Check this:</label> <input type=”checkbox” name=”check” …

Total answers: 7