From ba508f5b30489abd8baa8535350542d7e2ebc68c Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Thu, 23 Dec 2010 12:07:48 -0500 Subject: [PATCH] Improved NodeAdmin list_display options. Added use of default validators to JSONField and JSONFormField. --- admin/nodes.py | 6 +++++- models/fields.py | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/admin/nodes.py b/admin/nodes.py index 45a3172..a576d44 100644 --- a/admin/nodes.py +++ b/admin/nodes.py @@ -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): diff --git a/models/fields.py b/models/fields.py index 3e43c0f..19a6006 100644 --- a/models/fields.py +++ b/models/fields.py @@ -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 -- 2.20.1