GithubHelp home page GithubHelp logo

abogushov / django-admin-json-editor Goto Github PK

View Code? Open in Web Editor NEW
172.0 172.0 61.0 1.07 MB

Adds json-editor for JSONField in Django Administration

License: MIT License

Python 92.92% CSS 1.40% HTML 5.68%
django django-administration json json-editor

django-admin-json-editor's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @abogushov
  • ๐Ÿ‘€ Iโ€™m interested in ...
  • ๐ŸŒฑ Iโ€™m currently learning ...
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on ...
  • ๐Ÿ“ซ How to reach me ...

django-admin-json-editor's People

Contributors

abogushov avatar chubz avatar flyudvik avatar mlevental avatar xrmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-admin-json-editor's Issues

Unknown theme

When using default theme 'bootstrap3' I have an error in console
"Unknown theme bootstrap3"

how can I make the field optional not always required

as described in the documentation, i used a form for one of my fields

class ProductAdminForm(forms.ModelForm):
    class Meta:
        model = User
        fields = '__all__'
        widgets = {
            'editorial_data': JSONEditorWidget(DATA_SCHEMA, collapsed=False),
        }

but it seems that now I cannot save unless I provide that field. How can I make it optionaly

How this widget is shown?

Well, I realized that making a test and reading the example. So, I just add the example image into readme file. This more explicit presentation could helps interested users. Pull request: #20

List dependency on pathlib.

Hey there,

pip install django-admin-json-editor failed on my machine because I was missing pathlib. Maybe you could list that as a dependency in your install instructions?

Thanks!

Edit: I see this package is only meant for python 3. I'll close this.

Set and render new DATA_SCHEMA

Is there a way to set and render new data_schema on the page? The problem is to set json schema value on another field change event.

fontawesome4 not loaded

Since you auto set the iconlib to fontawesome4, can you also add the django-fontawesome (or django-font-awesome?) dependency to the plugin ? Icons aren't showing to the user if he doesn't have the font installed on his system.

how to set required fields ?

It looks like json-editor allows setting a required option to define what fields should be required or not.

I tried a schema like this:

HOST_ROLES_SCHEMA = {
    'type': 'array',
    'title': 'roles',
    'format': 'table',
    'items': {
        'type': 'object',
        'required': [
            'name',
            'tag',
        ],
        'properties': {
            'name': {
                'title': 'Name',
                'type': 'string',
                'format': 'text',
            },
            'tag': {
                'title': 'Tag',
                'type': 'string',
                'format': 'text',
            }
         }
    }
}

I also tried this version:
I tried a schema like this:

HOST_ROLES_SCHEMA = {
    'type': 'array',
    'title': 'roles',
    'format': 'table',
    'items': {
        'type': 'object',
        'properties': {
            'name': {
                'title': 'Name',
                'type': 'string',
                'format': 'text',
                'required': True,
            },
            'tag': {
                'title': 'Tag',
                'type': 'string',
                'format': 'text',
                'required': True,
            }
         }
    }
}

But I can keep saving the model with empty fields in django admin. Is this property not supported ? Do I need to add some custom code to handle it myself ? Not seeing any required html attribute or class name in the generated html output, I'm not sure where to go from there.

cache issue in django admin json editor

Hi,

I am using this extension(0.2.3) with Django 3.1.3
Added 1 entry via this form, when adding second entry with new data, sometimes it adds entry with first entry's data, it looks like it caching form data somewhere.

Please check the code below and help.

Thanks.

POLICY_FORM = {
  "title": "Policy",
  "type": "object",
  "required": [
    "Clicks",
    "Rate"
  ],
  "properties": {
    "Clicks": {
      "type": "number",
      "default": 0,
      "minimum": 0,
      # "maximum": 9900
    },
    "Rate": {
      "type": "number",
      "default": 0,
      "minimum": 0,
      # "maximum": 9900
    }
  }
 }

JSON_OPTION = {
    "theme": "html", 
    "disable_collapse": True,
    "disable_edit_json": True,
    "disable_properties": True,
  }
class PolicyForm(forms.ModelForm):
     policy = forms.JSONField(widget = JSONEditorWidget(POLICY_FORM, collapsed=False, editor_options=JSON_OPTION))

jdorn/json-editor is deprecated

Just realized when clicking on your readme link that the underlying jdorn/json-editor repository has been deprecated, and updates are now done on json-editor/json-editor.

Have you updated the static files with those from that new repo ?
Also, wouldn't it be simpler to use their cdn instead of copying the file ?

<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor/dist/jsoneditor.min.js"></script>

style display is strange

hello, I run a new porject like example, but the style display is strange. Is it a bug? How i can do?

environment:

  • Winodws 10
  • Python36
  • Django2.2+

ๅ›พ็‰‡

ๅ›พ็‰‡

Missing source map

You guys distribute a minified jsoneditor.min.js - could you please include the source map? Thanks

Json editor in StackedInline

Hello! Thanks for the work in this repository, it works great!

I had a problem and I did not know how to fix it:

I tried to place the form in an admin.StackedInline, then add it to an admin.ModelAdmin

the template worked correctly with the schema, however, sending the form caused error because the field was in None.

class AnotherModelAdminForm(ModelForm):
    class Meta:
        model = AnotherModel
        fields = '__all__'
        widgets = {
            'json_field': JSONEditorWidget(SCHEMA, collapsed=False),
        }
class AnotherModelAdmin(admin.StackedInline):
    model = AnotherModel
    form = AnotherModelAdminForm

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    inlines = [
        AnotherModelAdmin,
    ]

Can you think of a solution?

Thanks in advance

Documentation and examples

This lib looks great when you look at the options in the source code.

But it really lacks intuitive use case examples.

For instance:

Populate enum values

Hi, I'm having another issue regarding populating an enum field from db values.

Here's an example:

class HostAdminForm(forms.ModelForm):
    class Meta:
        model = Host
        fields = '__all__'
        HOST_ROLES_SCHEMA['items']['properties']['categoryId'] = {
            'title': 'category',
            'type': 'string',
            'enum': [1, 2, 3, 4, 5],   #  โ† We want to get the list of category ids from the db here
        }
        widgets = {
            'details': JSONEditorWidget(HOST_DETAILS_SCHEMA, collapsed=True),
        }

Any idea how we could proceed to do this ? Until now, we've asked our users to figure out what the id was and paste it in a text input :/

Widget render problem

Hi,
I had a problem with rendering the widget with any dict schema passed.
My project uses py2.7 and django 1.11.10

It seems that when pure dict is passed to the context it doesn't turn into a json string that schema attribute for the JS part likes to render.
it turns into a string that contains {u'title': 'sometitle'}

I've added json.dumps to assure json string is sent to the context and now widget renders the schema properly, and made a pull request #13

Issue with python 3.10

Hi,
I'm using python 3.10 and the library raised this issue due to an incompatibility:

  File "/usr/local/lib/python3.10/dist-packages/django/forms/boundfield.py", line 34, in __str__
    return self.as_widget()
  File "/usr/local/lib/python3.10/dist-packages/django/forms/boundfield.py", line 93, in as_widget
    return widget.render(
  File "/usr/local/lib/python3.10/dist-packages/django_admin_json_editor/admin.py", line 24, in render
    self.schema_updater(schema)
  File "/usr/local/lib/python3.10/dist-packages/django_admin_json_editor/admin.py", line 41, in schema_updater
    if isinstance(value, collections.Mapping):
AttributeError: module 'collections' has no attribute 'Mapping'

This way of importing the module has been deprecated since python 3.3:

DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' has been deprecated since Python 3.3, and in 3.10 it will stop working

It should be enough to change the import statement from import collection to from collections.abc import Mapping

UI is resized when using this package

I experienced a visual bug as soon as I started using this package, this is what my UI look like without it:

greenshot 2019-03-07 11 18 10

And now, after using the JSONEditorWidget in my admin.py
image

Basically, the UI looks resized, smaller, as if I had zoomed out. Probably a bad CSS rule applying undesired styles on the whole page instead of a sub element or something.

Using Python 3.6, Django 2.1.7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.