#34711: form.has_changed() is always True for IntegerChoices Enum Model Field
------------------------+--------------------------------------
     Reporter:  GHPS    |                    Owner:  nobody
         Type:  Bug     |                   Status:  new
    Component:  Forms   |                  Version:  4.2
     Severity:  Normal  |               Resolution:
     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 GHPS):

 * status:  closed => new
 * resolution:  invalid =>


Comment:

 Sorry for reopening this issue again...

 Replying to [comment:6 David Sanders]:
 >> If you want to manually override model form fields you must be sure to
 use the correct form field type. In the case of an IntegerField with
 choices you must use a ​TypedChoiceField A model form will use these
 automatically for an IntegerField by default.

 Thanks for the suggestion which I checked on the small test project
 mentioned above.

 So I've changed the form field type from ChoiceField to TypedCoiceField.
 {{{
 eAsset=forms.TypedChoiceField(choices=sampleModel.eAssets.choices)
 }}}

 This change, however, did nothing to the original problem: The
 form.has_changed() flag is alway True
 regardless of changing or not changing any field in the form.

 In the next step I completely removed said line and therefore relied on
 the
 form field automatically generated - voila, no problem.

 Seemingly the ChoiceField/TypedChoiceField methods convert the outgoing
 and incoming choice values which confuses the form.has_changed()
 detection.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34711#comment:7>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070189638fbecf-29dc8817-5960-4a21-94b5-22d828902fe0-000000%40eu-central-1.amazonses.com.

Reply via email to