That did it! That example was what I was looking for. The error handling led me astray, it's all taken care of. Thanks a lot.
On Jul 17, 2:42 am, Karen Tracey <kmtra...@gmail.com> wrote: > On Fri, Jul 16, 2010 at 6:27 PM, Joel Klabo <joelkl...@gmail.com> wrote: > > I am using modelForm to make a form for my Brew model. The form shows > > up and works fine. And saves it when I call save. But it does not > > catch the errors correctly. I set it up mostly based on this example: > > > from django.core.validators import ValidationError, NON_FIELD_ERRORS > > try: > > article.full_clean() > > except ValidationError, e: > > non_field_errors = e.message_dict[NON_FIELD_ERRORS] > > > First of all, NON_FIELD_ERRORS was unknown to django and caused an > > error. > > That was an error in the doc. The import should be: > > from django.core.exceptions import ValidationError, NON_FIELD_ERRORS > > > What I really want is to see a full code example of how to do this > > seemingly simple thing. Just a form from a model that allows users to > > create a new instance of the model and save it to the database. And > > how the errors are dealt with. Please help, I swear I have looked all > > through the docs. > > The simplest thing is the regular Django form idiom of calling is_valid() on > the form and re-displaying the form (now annotated with error information) > in the case where is_valid() returns False, > see:http://docs.djangoproject.com/en/1.2/topics/forms/#using-a-form-in-a-... > > The fragment of code you posted is from the documentation for the new model > validation feature, but it is not clear from what you have written that you > actually want/need to use that feature? For the simplest case, it isn't > needed. > > Karen > --http://tracey.org/kmt/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.