Opened 8 years ago
Closed 8 years ago
#29150 closed Cleanup/optimization (duplicate)
Pretty display of JSONField data in forms
| Reported by: | Andrew Wilson | Owned by: | |
|---|---|---|---|
| Component: | contrib.postgres | Version: | 2.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Herbert Fortes | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | yes |
Description
I think django.contrib.postgres.forms.jsonb.JSONField should be modified to display data in a more user-friendly way.
I am currently working around it with the following code, but I can't see any reason this shouldn't be the default behaviour. I'm happy to open a pull request if this is deemed useful.
import json
from django.contrib.postgres.forms.jsonb import InvalidJSONInput, JSONField
class PrettyJSONField(JSONField):
def prepare_value(self, value):
if isinstance(value, InvalidJSONInput):
return value
return json.dumps(
value,
indent=4,
sort_keys=True,
separators=(',', ': '),
ensure_ascii=False,
)
Attachments (2)
Change History (4)
by , 8 years ago
| Attachment: | before.png added |
|---|
by , 8 years ago
comment:1 by , 8 years ago
| Cc: | added |
|---|---|
| Triage Stage: | Unreviewed → Ready for checkin |
comment:2 by , 8 years ago
| Has patch: | unset |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
| Triage Stage: | Ready for checkin → Unreviewed |
| Type: | Uncategorized → Cleanup/optimization |
Duplicate of #26482 (closed as wontfix).
Note:
See TracTickets
for help on using tickets.
Hi,
IMHO it is a good idea.
Assign the ticket to yourself and do the PR.
Regards,
Herbert