On 15/03/11 14:42, Daniel Roseman wrote:
On Tuesday, March 15, 2011 2:36:45 PM UTC, Ben Dembroski wrote:
Hi Tom,
Thanks for your reply. (You're right, my example was lousy).
I did in fact try what you suggested earlier on, and got the the
following error:
AttributeError at /people/add/
'ValidationError' object has no attribute 'message_dict'
<snip>
I have this in the code:
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
and the code is currently so:
except ValidationError, e:
errormsg = e.message_dict[NON_FIELD_ERRORS]
form = EditPerson()
return render_to_response('personentry.html', { 'form' : form,
'errormsg': errormsg },context_instance=RequestContext(request))
Why are you trying to catch the ValidationError? The whole point is
that this is caught by the form's `clean()` method and then the
message appears in the error dictionary.
--
DR.
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
I knew someone was going to ask that :)
Mostly, it's a 'hacky' reason. In this occasion, the form is collecting
the date date in 'sections', Year, Month, Day. Only the Year is
required. The month and the day are optional. If the user leaves the
month and / or day fields blank, the view is inserting dummy values
into the database. (Don't ask me why, please).
At the moment, all the form is doing is checking to make sure each field
is an integer, and has the appropriate number of digits in each field.
However, it's still possible for a user to enter an invalid date -- Like
1956 - 02 - 31. The form is valid, but the date is not. Handling the
exception being raised by the model validation just seemed easier for
some reason.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.