Skip to content

Instantly share code, notes, and snippets.

@amatellanes
Last active February 19, 2021 09:55
Show Gist options
  • Save amatellanes/9920823 to your computer and use it in GitHub Desktop.
Save amatellanes/9920823 to your computer and use it in GitHub Desktop.
A Yes/No field for Django.
from django import forms
class Form(forms.Form):
field = forms.TypedChoiceField(coerce=lambda x: x =='True',
choices=((False, 'No'), (True, 'Yes')))
@dmenisdev
Copy link

I think you can fix this by adding the arguments: blank=True, null=True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment