Improve the editing experience for JSONFields.

Review Request #9405 — Created Nov. 27, 2017 and submitted


JSONFormField (through JSONField) had a pretty underwhelming editing
experience when used in forms. The text field would just contain a big
blob of serialized JSON content, which was pretty hard to read and

Now, the text field shows a pretty-printed representation of the JSON
data, with all keys sorted to make it easier to find the key you want.
When saved, the resulting data is once again condensed, but with the
keys remaining sorted in the database.

In order to do this, the old encoder argument for these classes has
been deprecated, with new encoder_cls and encoder_kwargs replacing
them. This allows the classes to decide when the encoder is constructed
and to provide additional arguments to control the behavior. Any
consumers providing a custom encoder today will not see the new editing
behavior, falling back on the legacy behavior instead.

Manually tested loading a JSON structure and editing it in the Admin UI.
Saw that the data was nicely indented and sorted. Saved it and saw that
the data was condensed in the database, but still sorted.

Unit tests pass.

  • 0
  • 0
  • 3
  • 1
  • 4
Description From Last Updated
  2. djblets/db/ (Diff revision 1)

    Can we list encoder first to match the JSONField constructor? Or change that one to match this?

  3. djblets/db/ (Diff revision 1)

    We don't actually emit a warning in this method.

  4. djblets/db/ (Diff revision 1)

    This should probably return self.encoder if it exists.

    1. No need. The property will be overridden in that case.

  5. djblets/db/ (Diff revision 1)

    Too many blank lines.

  1. Ship It!
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-1.0.x (a8fc9f9)