-
-
Notifications
You must be signed in to change notification settings - Fork 7k
PoC Add JSONBoundField to serializers (Fixes #4999) #5042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Looks good to me. Need to think a bit about how this plays with the |
@@ -82,6 +83,12 @@ def as_form_field(self): | |||
return self.__class__(self._field, value, self.errors, self._prefix) | |||
|
|||
|
|||
class JSONBoundField(BoundField): | |||
def as_form_field(self): | |||
value = json.dumps(self.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this display in a textarea or an input? Ideally an indented style and a textarea would probably be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Right now it does input, but I can see if I can make it do indented + textarea.
This does seem pretty valid, yup. |
I'm going to be out of the office until Apr. 22, and I've been trying to wrap some other stuff up before I go, so this has gotten pushed down the priority queue. I'll take it up again when I get back. |
I've updated my branch, I think addressing everybody's feedback so far. The updated code should play nicely with binary=True, although additional testing from someone who uses binary would be helpful. I've also changed the form to use a text area and indent the JSON. |
Nice improvement that, thanks! |
Per issue #4999, JSONFields are not rendered properly in the DRF
browsable API HTML forms. This patch attempts to fix that behavior by
introducing a JSONBoundField helper similar to the NestedBoundField
helper.
Description
I experienced #4999 today and put together this patch as an attempt to fix it. I'd appreciate any feedback as to whether this approach makes sense as this is my first dive into the DRF code. I could particularly use some guidance on what tests, documentation, etc. I should add.
./runtests.py reports all tests pass. tox reports failures in py35-djangomaster and py36-djangomaster, but those are present in my environment without this patch also. All other tox tests pass.