For example, `{"foo": "bar"}` would be displayed as `{'foo': 'bar'}`,
which is not valid JSON.
I believe the fix would be to add a special case in
`django.contrib.admin.utils.display_for_field` to call the `prepare_value`
of the `JSONField` (not calling `json.dumps` directly to take care of the
`InvalidJSONInput` case).
--
Ticket URL: <https://code.djangoproject.com/ticket/31157>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/31157#comment:1>
* owner: nobody => dbxnr
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31157#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/12308 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/31157#comment:3>
Comment (by Simon Charette):
The proposed patch is problematic as the first version coupled
`contrib.postgres` with `.admin` and the current one is based off the type
name which is brittle and doesn't account for inheritance.
It might be worth waiting for #12990 to land before proceeding here as the
patch will be able to simply rely of `django.db.models.JSONField` instance
checks from that point.
--
Ticket URL: <https://code.djangoproject.com/ticket/31157#comment:4>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"675ce4dd35702ce353006611ba30799c0c4b015f" 675ce4d]:
{{{
#!CommitTicketReference repository=""
revision="675ce4dd35702ce353006611ba30799c0c4b015f"
Refs #31157 -- Added tests for display_for_field() with empty JSONField.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31157#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"fc0f7f6c152766c92a95c74a02cc6fab79440ed8" fc0f7f6c]:
{{{
#!CommitTicketReference repository=""
revision="fc0f7f6c152766c92a95c74a02cc6fab79440ed8"
Fixed #31157 -- Fixed displaying read-only JSONField values in admin.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31157#comment:6>