Estoy tratando de cambiar el valor predeterminado de las casillas de verificación "verdadero/falso" a otro.
Desafortunadamente. Recibo un error de formulario: "la elección no es una de las opciones disponibles".
Por favor, dime ¿qué he hecho mal?
modelos.py
CHECKBOX_CHOICES = (('1', 'The first choice'), ('2', 'The Second Choice')) class Order(models.Model): paid = models.CharField(max_length=350, choices=CHECKBOX_CHOICES)
formularios.py
from django import forms from .models import Order class OrderCreateForm(forms.ModelForm): class Meta: model = Order fields = ['paid'] widgets = { 'paid': forms.CheckboxSelectMultiple() }
Si cambio de forms.CheckboxSelectMultiple()
a forms.CheckboxInput()
, recibo un error de formulario:
Select the correct value. True is not one of the choices available.
crear.html
<form action="." method="post" class="order-form"> {{ form.as_ul }} <p><input type="submit" value="Submit"></p> {% csrf_token %} </form>
html renderizado
<ul id="id_paid"> <li><label for="id_paid_0"><input type="checkbox" name="paid" value="" checked="" id="id_paid_0"> ---------</label> </li> <li><label for="id_paid_1"><input type="checkbox" name="paid" value="1" id="id_paid_1"> The first choice</label> </li> <li><label for="id_paid_2"><input type="checkbox" name="paid" value="2" id="id_paid_2"> The Second Choice</label> </li> </ul>
Es importante para mí, aunque sea una cosa pequeña.