Using checkbox in Django
I need to create a checkbox in django
models.py
class Listing(models.Model):
name = models.CharField(max_length=300)
check = models.BooleanField(default=False)
class AForm(forms.ModelForm):
class Meta:
model = Listing
name = forms.CharField()
check = forms.BooleanField(required=False)
views.py
def adddata(request):
if request.method == 'GET':
form = AForm(request.POST)
if form.is_valid():
form.save()
debugger output when running
(Pdb) form.cleaned_data
{'name': u'abcd', 'nagios': True}
(Pdb) connection.queries
[{u'time': u'0.001', u'sql': u"INSERT INTO `listing` (`name`,`nagios`)
VALUES ('abcd', 0)"}]
I have checked the createtable syntax and boolean is saved as tiny int
`nagios` tinyint(1) NOT NULL,
My doubt is why does form.save() replace 'True' with 0 when it saves.
How can i save the returned value of True in db.
I dont mind saving 0 or 1 in db . if i need to do so then whats the best
method for mapping True to 1
No comments:
Post a Comment