Hi,
I'm using following piece of code with ExtJS:
<code>
def extjs_validate_instance(instance):
"""Validate given Django model instance.
Return ExtJS formatted error response.
"""
try:
instance.full_clean() # Validate
except ValidationError, e:
opts = instance._meta
nice_messages = []
for fname, msgs in e.message_dict.items():
nice_messages.append({
'name' :
force_unicode(opts.get_field_by_name(fname)[0].verbose_name),
'error' : ', '.join(msgs),
})
response_obj = {
'success': False,
'items' : nice_messages}
raise ErrorResponse(status.HTTP_200_OK, response_obj)
</code>
Now it returns dict "nice_messages" which contains fieldname and
message(s) associated with that field.
> <mailto:
django...@googlegroups.com>.
> <mailto:
django-users%2Bunsu...@googlegroups.com>.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
--
Jani Tiainen
- Well planned is half done and a half done has been sufficient before...