Skip to content

Commit 09f8eab

Browse files
committedNov 15, 2015
Fixed rendering and empty values
1 parent 4e2bbfb commit 09f8eab

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed
 

‎jsoneditor/forms.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55

66
from django.conf import settings
77

8+
import json
9+
810
class JSONEditor(Textarea):
911
class Media:
1012
js = (
1113
getattr(settings,"JSON_EDITOR_JS",settings.STATIC_URL+'jsoneditor/jsoneditor.js'),
12-
getattr(settings,"JSON_EDITOR_JS",settings.STATIC_URL+'django-jsoneditor/django-jsoneditor.js'),
14+
settings.STATIC_URL+'django-jsoneditor/django-jsoneditor.js',
1315
)
1416
css= {'all': ( getattr(settings, "JSON_EDITOR_CSS",settings.STATIC_URL+'jsoneditor/jsoneditor.css'),)}
1517

1618
def render(self, name, value, attrs=None):
19+
if not isinstance(value,basestring):
20+
value = json.dumps(value)
1721
input_attrs = {'hidden':True}
1822
input_attrs.update(attrs)
1923
if not 'class' in input_attrs:

‎jsoneditor/static/django-jsoneditor/django-jsoneditor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ django.jQuery(function() {
1111
if($nxt.attr("name") == name) {
1212
continue;
1313
}
14-
var value;
14+
var value = {};
1515
try {
1616
value = JSON.parse($f[0].value);
1717
} catch(e) {

‎testapp/admin.py

+12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@
33
from . import models
44
# Register your models here.
55

6+
class TestStackedInline(admin.StackedInline):
7+
model = models.TestSubModel1
8+
extra = 1
9+
10+
class TestTabularInline(admin.StackedInline):
11+
model = models.TestSubModel2
12+
extra = 1
13+
614
class TestAdmin(admin.ModelAdmin):
15+
inlines = (
16+
TestStackedInline,
17+
TestTabularInline
18+
)
719
pass
820

921
admin.site.register(models.TestModel,TestAdmin)

‎testapp/migrations/0001_initial.py

+16
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@ class Migration(migrations.Migration):
2020
('test_django_jsonfield', jsoneditor.fields.django_jsonfield.JSONField(help_text=b'Test JSON editor for the django-jsonfield from https://github.com/bradjasper/django-jsonfield', null=True, verbose_name=b'Test JSON 2', blank=True)),
2121
],
2222
),
23+
migrations.CreateModel(
24+
name='TestSubModel1',
25+
fields=[
26+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
27+
('test_inline_json_field', jsoneditor.fields.django_json_field.JSONField(default='null', help_text=b'Test JSON editor for the django-json-field from https://github.com/derek-schaefer/django-json-field', null=True, verbose_name=b'Test JSON 1', blank=True)),
28+
('par', models.ForeignKey(to='testapp.TestModel')),
29+
],
30+
),
31+
migrations.CreateModel(
32+
name='TestSubModel2',
33+
fields=[
34+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
35+
('test_inline_json_field', jsoneditor.fields.django_json_field.JSONField(default='null', help_text=b'Test JSON editor for the django-json-field from https://github.com/derek-schaefer/django-json-field', null=True, verbose_name=b'Test JSON 1', blank=True)),
36+
('par', models.ForeignKey(to='testapp.TestModel')),
37+
],
38+
),
2339
]

‎testapp/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@
77
class TestModel(models.Model):
88
test_django_json_field = JSONField1(verbose_name="Test JSON 1",null=True,blank=True,help_text="Test JSON editor for the django-json-field from https://github.com/derek-schaefer/django-json-field")
99
test_django_jsonfield = JSONField2(verbose_name="Test JSON 2",null=True,blank=True,help_text="Test JSON editor for the django-jsonfield from https://github.com/bradjasper/django-jsonfield")
10+
11+
class TestSubModel1(models.Model):
12+
par = models.ForeignKey(TestModel)
13+
test_inline_json_field = JSONField1(verbose_name="Test JSON 1",null=True,blank=True,help_text="Test JSON editor for the django-json-field from https://github.com/derek-schaefer/django-json-field")
14+
15+
class TestSubModel2(models.Model):
16+
par = models.ForeignKey(TestModel)
17+
test_inline_json_field = JSONField1(verbose_name="Test JSON 1",null=True,blank=True,help_text="Test JSON editor for the django-json-field from https://github.com/derek-schaefer/django-json-field")

0 commit comments

Comments
 (0)
Please sign in to comment.