django-unfold
django-unfold copied to clipboard
Add support for django-jsonform
ref: https://github.com/bhch/django-jsonform
I added it in my app but I can't see the JS stuff so probably is missing some integration specific to load the different HTML and JS for this library.
So I was able to integrate it but is a workaround:
ITEMS_SCHEMA = {
'type': 'array',
'items': {
'type': 'integer'
}
}
formfield_overrides = {
JSONField: {
"widget": JSONFormWidget(schema=ITEMS_SCHEMA),
}
}
As you can see the parameter schema
is custom one and overriding let's to load the right field but it is missing that parameter.
With this workaround I am placing twice the schema in the admin and the model but it should get it from the model.
I tried patching the widgets.py to add the new unfold field with:
try:
from django_jsonform.widgets import JSONFormWidget
class UnfoldAdminJSONFormWidget(JSONFormWidget):
def __init__(self, attrs=None, schema=()):
super().__init__(attrs, schema)
except ImportError:
class UnfoldAdminJSONFormWidget:
def __init__(self, *args, **kwargs):
raise UnfoldException("django-jsonform not installed")
And in admin.py:
try:
from django_jsonform.widgets import JSONFormWidget
HAS_JSONFORM = True
except ImportError:
HAS_JSONFORM = False
if HAS_JSONFORM:
FORMFIELD_OVERRIDES.update(
{
models.JSONField: {"widget": UnfoldAdminJSONFormWidget},
}
)
But I am not able to get the schema
parameter passed in the model.
Massive thumbs up for this - @lukasvinclav if you're keen on this, then in the new year when I'm back in office I could discuss partly sponsoring the feature, as it would be mega useful for me to connect to postgres' JSONField.
@Mte90 perhaps your organisation could co-sponsor the work, if it's for something that ends up client-facing?
It'll make a nice pairing with the work on django-svelte-jsoneditor - which you might also be interested in, @Mte90, if you're doing jsony things with django!
At the end I switched to https://pypi.org/project/django-select2/ as it wasn't working great also on frontend (I am in a prototype phase right now) and the content value wasn't working with that package (I tried to get jsonform on backend and select2 on frontend).
The integration was more nicer also if I have an issue with the JS library used https://github.com/select2/select2/issues/6287
Ah right, OK. I'm going to give it a try now, I've been searching for a jsonschema form integration for a long while now. There are a few offerings out there but I hadn't come across this, and it looks much more comprehensive and better maintained than the others. I'll report back.
After a couple of hours of playing I'd say this is a bit of a struggle in some ways but can be achieved overall. It's reasonably well designed fin terms of the architectural choices made.
The styling looks horrible on top of unfold, but it is just about usable. So I think my verdict is I'm going to try it out a bit more and if I start using it in a bit more anger on customers projects I'll come back here and give this a poke that I'm willing to sponsor.
Pic attached for prrof of concept that it's possible to render the widget into unfold.
the screenshot is missing :-)
the screenshot is missing :-)
fixed!
For third party application integration you can contact us here https://unfoldadmin.com/