9π
β
If you want to prevent displaying of -------
choice, you should specify empty_label=None
in your form field.
Also, I recomend you to use BooleanField for model and TypedChoiceField for form:
models.py:
class Medication(models.Model):
Allergies = models.BooleanField('Allergies:')
forms.py:
class MedicationForm(forms.ModelForm):
YESNO_CHOICES = ((0, 'No'), (1, 'Yes'))
Allergies = forms.TypedChoiceField(
choices=YESNO_CHOICES, widget=forms.RadioSelect, coerce=int
)
π€Serhii Holinei
1π
Using the BigIntegerField, you can also set the default=0 or whatever choice you would like it to be.
π€imapotatoe123
- [Django]-'ascii' codec can't decode byte 0xe2 in position 5367: ordinal not in range(128)
- [Django]-Django ORM: Joining QuerySets
- [Django]-Error on django runserver β OverflowError: getsockaddrarg: port must be 0-65535
- [Django]-Django Elastic Search: AttributeError: type object 'PostDocument' has no attribute 'Django'
- [Django]-Cannot urlencode() after storing QueryDict in session
Source:stackexchange.com