diff options
author | Magnus Hagander | 2020-02-20 14:54:42 +0000 |
---|---|---|
committer | Magnus Hagander | 2020-02-20 14:54:42 +0000 |
commit | e96fbcff738bdda87da41cd8762828c35acda205 (patch) | |
tree | 9822e473a51965b6a09e097a7ed8d214e15e0f1b /postgresqleu/util/widgets.py | |
parent | 8d2321d025de8f89dc6f42cb610209ce1ee4a053 (diff) |
Make json widget handle null values and nested dicts
Diffstat (limited to 'postgresqleu/util/widgets.py')
-rw-r--r-- | postgresqleu/util/widgets.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/postgresqleu/util/widgets.py b/postgresqleu/util/widgets.py index 02d2fb30..8994453c 100644 --- a/postgresqleu/util/widgets.py +++ b/postgresqleu/util/widgets.py @@ -44,7 +44,12 @@ class PrettyPrintJsonWidget(forms.Textarea): # This is mighty ugly -- we parse the json and then turn it back into json. # Luckily this isn't called often :) try: - value = json.dumps(json.loads(value), indent=2) + if value is not None: + if isinstance(value, dict): + # Already a dict, so just turn it into json + value = json.dumps(value, indent=2) + else: + value = json.dumps(json.loads(value), indent=2) except ValueError: # Don't try to do anything if it's not valid json pass |