Skip to main content

Django form widget form JSONField

Project description

django-jsoneditor-widget

Django form widget form JSONField

Demo

It look like this.

demo image

Install

  • Install: pip install django-jsoneditor-widget
  • Settings:
    INSTALLED_APPS = [
        # some apps ....
        'jsoneditor',
        # other apps ...
    ]
    

Create model

from django.db import models
from django.contrib.postgres.fields import JSONField


class Book(models.Model):
    name = models.CharField(max_length=150)
    information = JSONField()

    def __str__(self):
        return self.name

Admin site settings

  • Use ModelAdmin

    from django.contrib import admin
    
    from jsoneditor.admin import JSONFieldModelAdmin
    
    from .models import Book
    
    
    admin.site.register(Product, JSONFieldModelAdmin)
    
  • Use mixin

    from django.contrib import admin
    
    from jsoneditor.admin import JSONFieldAdminMixin
    
    from .models import Book
    
    
    @admin.register(Book)
    class BookModelAdmin(JSONFieldAdminMixin, admin.ModelAdmin):
        pass
    
  • Use custom widget to specify jsoneditor options

    from django.contrib import admin
    from django.contrib.postgres.fields import JSONField
    
    from jsoneditor.forms import JSONEditor
    
    from .models import Book
    
    
    class TextJSONEditor(JSONEditor):
        jsoneditor_options = {
            "mode": "text"
        }
    
    
    @admin.register(Book)
    class BookModelAdmin(admin.ModelAdmin):
        formfield_overrides = {
            JSONField: {"widget": TextJSONEditor}
        }
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-jsoneditor-widget-1.3.2.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

django_jsoneditor_widget-1.3.2-py3-none-any.whl (577.1 kB view details)

Uploaded Python 3

File details

Details for the file django-jsoneditor-widget-1.3.2.tar.gz.

File metadata

  • Download URL: django-jsoneditor-widget-1.3.2.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

File hashes

Hashes for django-jsoneditor-widget-1.3.2.tar.gz
Algorithm Hash digest
SHA256 0271a171a4cd9cd2e798eb1dd4845b726b67586952310ac92fc7d12056e0e187
MD5 1d1f345e05f1295067df73f0dcd70859
BLAKE2b-256 e2cdd6784514c329bf96bc322304b173de071ae0f52070a588ce6e1832369dfd

See more details on using hashes here.

File details

Details for the file django_jsoneditor_widget-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: django_jsoneditor_widget-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 577.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

File hashes

Hashes for django_jsoneditor_widget-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 919d81a6291e46e8209f358d896eee2b23248694a390d0325a10ee369b2f4448
MD5 49b07d47451fa371baee3f0b41c1fc8e
BLAKE2b-256 a7883e01548392271536be0af345b83d12f3572b0543efbdaa9ace7783fe3961

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page