Snippet List
from http://www.djangosnippets.org/snippets/792/
from utils.extjs import ExtJSONEncoder
from django.utils.safestring import mark_safe
class TestForm(forms.ModelForm):
class Meta:
model = TestModel
def as_ext(self):
return mark_safe(simplejson.dumps(self,cls=ExtJSONEncoder))
This is a subclass of Django's built-in JSONEncoder that adds the ability to output form and field objects as ExtJS-compatible config objects.
Simple example:
from django.utils import simplejson
json = {
'data': [],
'success': True,
'metaData': {
'fields': SFY09RDOForm(),
'root': 'data',
'successProperty': 'success'
},
}
return HttpResponse(simplejson.dumps(json, cls=ExtJSONEncoder))
Where SFY09RDOForm is a subclass of django.forms.Form.
6/20/2008: Updated to pass on the help_text parameter (useful in combination with this override in ext: http://extjs.com/forum/showthread.php?t=36642)
3 snippets posted so far.