#27433: ModelForm with BooleanField can not save False/unchecked
-------------------------------------+-------------------------------------
     Reporter:  Christian Pedersen   |                    Owner:  Ingo
                                     |  Klöcker
         Type:  Bug                  |                   Status:  closed
    Component:  Forms                |                  Version:  1.10
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Ingo Klöcker):

 * status:  assigned => closed
 * resolution:   => needsinfo


Comment:

 I could not reproduce the problem. The following test passes with Django
 1.10.2.

 {{{
 class Test(TestCase):
     def test_27433(self):
         class Model(models.Model):
             starred_only = models.BooleanField(default=False)

         class Form(forms.ModelForm):
             starred_only = forms.BooleanField(required=False)

             class Meta:
                 model = Model
                 fields = ['starred_only']

         m = Model(starred_only=True)
         f = Form({}, instance=m)
         self.assertTrue(f.is_valid())
         self.assertFalse(m.starred_only)
 }}}

 The test fails if I change
 {{{
                 fields = ['starred_only']
 }}}
 to
 {{{
                 fields = []
 }}}
 but I think that's expected behavior.

 See also https://docs.djangoproject.com/en/1.10/topics/forms/modelforms
 /#the-save-method (which I think you did already read).

 Please provide a test case that demonstrates your bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/27433#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.9c58ad811370061b62772063ed4b1aaa%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to