Is there a simple way to add my own error messages to a newform object
so that I don't have to pass extra stuff to template context and
.as_table() takes care of displaying the error for me?
That is, can anyone point out the utter stupidity of doing stuff like:
form = SomeForm(post_data)
if form.is_valid():
obj = SomeModel(**form.clean_data) # well, ignore this...
try:
obj.save()
except ...: # catching an INSERT error on a unique field here
investigate error, rollback transaction, etc.
# and here I want to do something like:
form.add_error(..., "Failed to save this data because ..")
# or perhaps
form['some_field'].add_error("blah blah") / form.some_field.
...
else:
return HttpResponseRedirect(...)
...
simply render template with an {{ form.as_table }} or whatever
I looked at the source and doing this works:
from django.newforms.util import ErrorList
form.errors.update(some_field=ErrorList([u'blah blah'])) # assuming no
errors already
but it seems awfully hackish?
And what about adding non-field errors (currently associated in the
hash with '__all__', it seems)?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---