#20202: BaseModelForm uses model_to_dict to provide initial, causes problems for
ModelChoiceField with non-pk to_field_name
-------------------------------+------------------------------------
     Reporter:  valtron2000@…  |                    Owner:  nobody
         Type:  New feature    |                   Status:  new
    Component:  Forms          |                  Version:  1.5
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------
Changes (by valtron2000@…):

 * type:  Bug => New feature


Comment:

 I see, `to_field_name` is supposed to be mostly internal, because it's
 usually set by `ForeignKey.formfield`
 
(https://github.com/django/django/blob/master/django/db/models/fields/related.py#L1244).
 The only time the user has to provide it is if they're defining the field
 manually rather than though `Meta.fields`. I agree that this should be
 documented.

 However, my use case is: my FKs use the PK, but my models also have a uuid
 field. I don't want to expose PKs in the front end, so I was in the
 process of (as of now, incorrectly) using `to_field_name` to use the uuid
 for a bunch of fields. Therefore, I'm turning this into a feature request.

 I know that a lot of people currently use `model_to_dict` as it stands, so
 changing its behaviour isn't an option. It would be better to make a
 private `_get_initial_from_instance` that works the same but returns the
 instance instead of the PK for FK fields, and then it becomes the form
 field's responsibility to turn the instance into an HTML form field value.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20202#comment:3>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to