Opened 6 years ago
Closed 6 years ago
#31043 closed Bug (duplicate)
Form with ModelChoiceField and disabled failed when the initial is model instance.
| Reported by: | Eran Keydar | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | 3.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Got this issue in some more complex example, narrows down to this scenario:
class Form1(forms.Form):
user = forms.ModelChoiceField(
queryset=get_user_model().objects.all(),
disabled=True,
initial=get_user_model().objects.get(pk=1)
)
label = forms.CharField()
Then
In [12]: f = Form1(data={'label':'aaa'})
In [13]: f.is_valid()
Out[13]: False
In [14]: f.errors
Out[14]: {'user': ['Select a valid choice. That choice is not one of the available choices.']}
If the initial changed to the pk itself, everything works fine
Change History (1)
comment:1 by , 6 years ago
| Component: | Uncategorized → Forms |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
| Summary: | From with ModelChoiceField and disabled failed when the initial is model instance and not pk → Form with ModelChoiceField and disabled failed when the initial is model instance. |
| Type: | Uncategorized → Bug |
| Version: | 2.2 → 3.0 |
Note:
See TracTickets
for help on using tickets.
Duplicate of #30014. This is fixed in Django 3.0.