Closed Flimm closed 3 years ago
I'm trying to use it with the models.JSONField. Doesn't work. Have you found something that works maybe?
I'm trying to use it with the models.JSONField. Doesn't work. Have you found something that works maybe?
What Doesn't work? value_json = models.JSONField(blank = True, null = True) and in model form override fields with: widget=JSONEditorWidget(height = '200px') defaults.update({'widget': widget})
Like this work!Good Luck
The documentation is using the django.contrib.postgres.fields
version of JSONField which will soon be deprecated. The reason it wasn't working for me at first was because I was using the django.db.models
in my models.py and used the documentations version to have it run in my admin.
Here is my admin.py
:
from django.contrib import admin
from django.db import models # This is the important part here
from django_json_widget.widgets import JSONEditorWidget
from .models import Form, FormSubmission
@admin.register(FormSubmission)
class FormSubmissionAdmin(admin.ModelAdmin):
formfield_overrides = {
models.JSONField: {'widget': JSONEditorWidget}
# ^^^^^^^^^^^^^^^^ this is the part you want to change.
}
Just looking now that #48 #46 are both pull requests that are updating the README.md
@elebumm thanks. That fixed it for me. This should be added to the README ;)
Fixed in the new version with PR #46
Django 3.1 introduced a new
django.db.models.JSONField
(distinct from the PostgreSQL one).Does this package support it?