Added sortable_field_name to the collection member inline for grappelli.
[philo.git] / forms / fields.py
1 from django import forms
2 from django.core.exceptions import ValidationError
3 from django.utils import simplejson as json
4 from philo.validators import json_validator
5
6
7 __all__ = ('JSONFormField',)
8
9
10 class JSONFormField(forms.Field):
11         default_validators = [json_validator]
12         
13         def clean(self, value):
14                 if value == '' and not self.required:
15                         return None
16                 try:
17                         return json.loads(value)
18                 except Exception, e:
19                         raise ValidationError(u'JSON decode error: %s' % e)