Opened 7 years ago

Closed 7 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)

before.png (9.2 KB ) - added by Andrew Wilson 7 years ago.
after.png (11.3 KB ) - added by Andrew Wilson 7 years ago.

Download all attachments as: .zip

Change History (4)

by Andrew Wilson, 7 years ago

Attachment: before.png added

by Andrew Wilson, 7 years ago

Attachment: after.png added

comment:1 by Herbert Fortes, 7 years ago

Cc: Herbert Fortes added
Triage Stage: UnreviewedReady for checkin

Hi,

IMHO it is a good idea.

Assign the ticket to yourself and do the PR.

Regards,
Herbert

comment:2 by Tim Graham, 7 years ago

Has patch: unset
Resolution: duplicate
Status: newclosed
Triage Stage: Ready for checkinUnreviewed
Type: UncategorizedCleanup/optimization

Duplicate of #26482 (closed as wontfix).

Note: See TracTickets for help on using tickets.
Back to Top