-
Notifications
You must be signed in to change notification settings - Fork 124
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
Enhancement: raw JSON admin fields for DictField and ListField (with sample code) #29
Comments
(I just edited the SerializedObjectWidget code to remove a pointless serialize-deserialize step in DjangoJSONEncoder, which was messing up sub-sub-objects.) |
Any opinions from other contributors? I don't have any (yet). |
Hey, first of all thanks for sharing this. As this looked like it would pretty much solve my trouble with the ListField i tried to implement it, but ... i run into an issue with the Field part in If i use it as stated i get: then i thought i need to define the Field-Type i'm using inside the ListField, so i tried:
with the following result: As a beginner here i would be grateful if you could point me into a direction to solve this. Thanks a lot, |
Oh no .... damn it ..... feeling like the ultra noob ;) Just fixed it .... it was just an import missing in my models.py:
Thank you really for sharing your code ... Best, |
FWIW, I think this should be the default behavior for DictField fields. This then opens up the admin interface by default and enables other things like djangorestframework to work properly. |
Thanks for sharing this code! Very helpful! |
Hi --
I've been thinking that, until someone gets around to putting a nice interface on DictFields and ListFields, it would be nice to be able to edit them as raw JSON in the admin -- just show a Textarea with the contents of the field.
So to that end, I put together the following SerializedObjectWidget:
All this does is take an arbitrary Python object (which can include model instances), encode it as JSON, and put it in a Textarea to display. Then on save it takes the results and decodes them back into a Python object including model instances. So it's pretty agnostic about what you use it for, but in particular it should work fine for DictFields and ListFields. Here's how I'm using it in my project (in models.py):
The result in the admin looks like this: http://imgur.com/qExPZ
So, not something you'd want just any user to have access to, but usable if you know what you're doing.
This is working for me so far, but I haven't used it much and there might be all kinds of edge cases and security holes. I just wanted to throw it out there as an option to fold into DictField and ListField until something better comes along.
What do you think?
Thanks,
Jack
The text was updated successfully, but these errors were encountered: