jmrivas86 / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
MIT License
440 stars 88 forks source link

Does this support the new django.db.models.JSONField? #49

Closed Flimm closed 3 years ago

Flimm commented 4 years ago

Django 3.1 introduced a new django.db.models.JSONField (distinct from the PostgreSQL one).

Does this package support it?

lrusik commented 4 years ago

I'm trying to use it with the models.JSONField. Doesn't work. Have you found something that works maybe?

MaxSpacer commented 4 years ago

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

elebumm commented 3 years ago

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.
    }
elebumm commented 3 years ago

Just looking now that #48 #46 are both pull requests that are updating the README.md

ashleyconnor commented 3 years ago

@elebumm thanks. That fixed it for me. This should be added to the README ;)

jmrivas86 commented 3 years ago

Fixed in the new version with PR #46