Improved NodeAdmin list_display options. Added use of default validators to JSONField...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 23 Dec 2010 17:07:48 +0000 (12:07 -0500)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 23 Dec 2010 17:07:48 +0000 (12:07 -0500)
admin/nodes.py
models/fields.py

index 45a3172..a576d44 100644 (file)
@@ -4,7 +4,11 @@ from philo.models import Node, Redirect, File
 
 
 class NodeAdmin(TreeEntityAdmin):
-       pass
+       list_display = ('slug', 'view', 'accepts_subpath')
+       
+       def accepts_subpath(self, obj):
+               return obj.accepts_subpath
+       accepts_subpath.boolean = True
 
 
 class ViewAdmin(EntityAdmin):
index 3e43c0f..19a6006 100644 (file)
@@ -200,7 +200,11 @@ class TemplateField(models.TextField):
 
 
 class JSONFormField(forms.Field):
+       default_validators = [json_validator]
+       
        def clean(self, value):
+               if value == '' and not self.required:
+                       return None
                try:
                        return json.loads(value)
                except Exception, e:
@@ -231,9 +235,7 @@ class JSONDescriptor(object):
 
 
 class JSONField(models.TextField):
-       def __init__(self, *args, **kwargs):
-               super(JSONField, self).__init__(*args, **kwargs)
-               self.validators.append(json_validator)
+       default_validators = [json_validator]
        
        def get_attname(self):
                return "%s_json" % self.name