#36482: Admin renders complex PKs incorrectly
-------------------------------+-----------------------------------------
Reporter: David Sanders | Type: Bug
Status: new | Component: contrib.admin
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-----------------------------------------
Admin creates links to edit/history/etc pages by rendering the PK directly
as a string - either explicitly in Python or implicitly in one of the
templates.
However when the instance is retrieved in `get_object()` it uses
`field.to_python(value)` like so:
https://github.com/django/django/blob/a3882876927a819ca982ea61353945e9d86f3659/django/contrib/admin/options.py#L886
This creates an asymmetrical serialisation-deserialisation process which,
while is fine for integers, will fail for things more complex.
The correct serialisation of pk would be the inverse of `to_python()`:
`field.value_to_string(obj)`.
Note this is related to #35953: The fix for this would also be useful to
get composite PKs working - at least for rendering the PK.
I noticed this while trying out `DateTimeRangeField()` as part of the PK
for temporal models as the `valid_time` – this field type uses specific
json serialisation which is quite verbose in the URL but works (have
tested it will post proposed patch in a draft PR)
--
Ticket URL: <https://code.djangoproject.com/ticket/36482>
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 visit
https://groups.google.com/d/msgid/django-updates/01070197b1aea799-47c1eddd-7bcf-4ce7-843a-27d45d72e4e1-000000%40eu-central-1.amazonses.com.