django-jsonform icon indicating copy to clipboard operation
django-jsonform copied to clipboard

Is there a way to use this widget outside of admin site?

Open arpanpreneur opened this issue 2 years ago • 9 comments

Is there a way to use this JSONForm Widget outside of Django Admin Site?

I want to use this widget in a custom view with template.

arpanpreneur avatar Mar 21 '23 03:03 arpanpreneur

I've not tried it but since it's just a regular Django form field and widget, it should be possible to use it outside the admin.

Did you try it? What didn't work?

bhch avatar Mar 21 '23 06:03 bhch

Hi, I tried, with a little fiddling with the crispy settings, I was able to use it outside django admin site. Currently to make the styles consistent, I am injecting classes and styles to the jsonformwidget dom nodes, but a better way to customize the style would be very appreciable.

arpanpreneur avatar Mar 25 '23 08:03 arpanpreneur

Yes, theming support is definitely on my to-do list. But that won't be anytime soon.

I had initially created this just for using inside the admin and did not plan much for other use cases. So the html structure and class names are all a mess right now.

This would require rewriting significant portion of the UI generator.


Anyway, for frontend stuff, I'd recommend react-jsonschema-form. It supports theming (bootstrap, material etc) out of the box.

bhch avatar Mar 25 '23 10:03 bhch

Hi what settings we need to change to use this ?

pritamfocal avatar Apr 17 '23 11:04 pritamfocal

I've not tried it but since it's just a regular Django form field and widget, it should be possible to use it outside the admin.

Did you try it? What didn't work?

Hi I tried to use outside the admin page but its not showing the fileds values ?...

I have used like this {{ ml_settings.as_p }}

but its working fine in the Admin tool

pritamfocal avatar Apr 17 '23 11:04 pritamfocal

Hi, I tried, with a little fiddling with the crispy settings, I was able to use it outside django admin site. Currently to make the styles consistent, I am injecting classes and styles to the jsonformwidget dom nodes, but a better way to customize the style would be very appreciable.

Hi Arpan, do you know which settings you add to get it worked outside admin tool. :) ?

pritamfocal avatar Apr 17 '23 12:04 pritamfocal

I, too, would like to know how to use this outside of an Admin section of a site? Any tips out there?

I'm on python 3.12.1 and Django 5.

nathan-gilbert avatar Feb 09 '24 23:02 nathan-gilbert

Try using {{ object.media }}. it worked for me.

pritamfocal avatar Feb 10 '24 07:02 pritamfocal

Try using {{ object.media }}. it worked for me.

Ditto. The problem here is that if you try to use a ModelForm in an entirely custom template, the media won't be included (which is how the django-jsonform css/js gets in normally in the Django admin). You have to add {{ form.media }} to your head block yourself if using a custom template.

calebsyring avatar Mar 14 '24 19:03 calebsyring