这是我的models.py中的内容:
class GraduationApp(models.Model):
id = models.AutoField(primary_key=True)
addr_to_photographer = models.NullBooleanField(blank=True, null=True)
class Meta:
db_table = u'graduation_app'
这是我的 forms.py 中的内容:
BOOLEAN_CHOICES = (
(None,' '),
(True,'Yes'),
(False,'No')
)
class EnterAppForm(ModelForm):
addr_to_photographer = forms.ChoiceField(choices=BOOLEAN_CHOICES, required=False)
class Meta:
model = GraduationApp
fields=('addr_to_photographer')
这是我的模板中的内容:
Address to Photographer? {{ form.addr_to_photographer }}
这是我在views.py中的保存:
print 'your POST address_to_photographer is', request.POST['addr_to_photographer']
print 'your form.cleaned_data addr_to_photographer is', form.cleaned_data['addr_to_photographer']
updapp = GraduationAppForm.objects.get(id=request.POST['app_id'])
updapp.addr_to_photographer = form.cleaned_data['addr_to_photographer']
updapp.save()
print 'YOU JUST UPDATED ME', updapp.person.eid, 'ADDR TO PHOTO IS', updapp.addr_to_photographer
我收到这些打印声明:
您的 POST address_to_photographer 为 False
你的 form.cleaned_data addr_to_photographer 是 False
你刚刚更新了我 oy278 地址到照片是 (u'False',)
但是当我查看 MySQL 中的字段时,它里面有一个 1,而不是 0。帮助!