#28316: ModelChoiceField to_field_name doesn't work if it's different from the
model field's to_field
--------------------------------+------------------------------------------
Reporter: László Károlyi | Owner: László Károlyi
Type: Bug | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------------
Comment (by Marc Gibbons):
Taking a stab at a fix for this. Looked at few different options –
including `ModelChoiceField` and `model_to_dict`, all of which (including
this one) feeling a bit hacky.
It really comes down to a problem of generating initial values to the
`ModelForm` when an instance is provided and is used as the source of
initial values. Getting the full context of the ForeignKey, its
`to_field`, and whether or not the "initial" value came from the
`instance` or from the `initial` kwargs of the constructor, isn't feasible
from the `ModelChoiceField` class in isolation.
PR: https://github.com/django/django/pull/15025
--
Ticket URL: <https://code.djangoproject.com/ticket/28316#comment:12>
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/065.26af202c3252c6f441f014fd38c6b21f%40djangoproject.com.