Skip to content

Instantly share code, notes, and snippets.

@amatellanes
Last active February 19, 2021 09:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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')))
@CARocha
Copy link

CARocha commented Sep 8, 2020

if i put this field requited=False i have this error Field 'field' expected a number but got '' any idea put this field not required,
in my models put field null=True and blank=True but nothing the same error?

any idea to solve this

@dennisvd
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