Django BooleanField as a dropdown

What you can do is add "choices" key word to your BooleanField in your models.py

class MyModel(models.Model):
    BOOL_CHOICES = ((True, 'Yes'), (False, 'No'))

    attending = models.BooleanField(choices=BOOL_CHOICES)

With a modelform

TRUE_FALSE_CHOICES = (
    (True, 'Yes'),
    (False, 'No')
)
class MyModelForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = ('attending',)
        widgets = {
            'attending': forms.Select(choices=TRUE_FALSE_CHOICES)
        }

I believe a solution that can solve your problem is something along the lines of this:

TRUE_FALSE_CHOICES = (
    (True, 'Yes'),
    (False, 'No')
)

boolfield = forms.ChoiceField(choices = TRUE_FALSE_CHOICES, label="Some Label", 
                              initial='', widget=forms.Select(), required=True)

Might not be exact but it should get you pointed in the right direction.

Tags:

Python

Django