abogushov / django-admin-json-editor

Adds json-editor for JSONField in Django Administration
MIT License
173 stars 61 forks source link

cache issue in django admin json editor #38

Open mavajikitl opened 3 years ago

mavajikitl commented 3 years ago

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))