General flow for forms should develop to this:

form = MyModelForm(data)
if form.is_valid():
    try:
        form.save()
    except ValidationError, error:
        form.add_error(None, error)
    else:
        return redirect('success')
return render_failure(form)

While handling such case in custom view is simple. But handling this case, 
when using views from Django is completely different level. In generic 
views it is still possible to override `form_valid` to handle 
IntegrityError or other required exception, but it is not possible to do so 
in ModelAdmin 'add_view' and 'change_view'. There it requires rebuilding 
the whole context which is duplication of about 30 lines from '
changeform_view'.

Dne čtvrtek 26. listopadu 2015 13:30:50 UTC+1 Tom Christie napsal(a):
>
> > Append form's non_field_errors with message like
>
> Given that the IntegrityError doesn't occur until the point of .save(), 
> it's not obvious how that'd work in terms of the Forms API.
> You're absolutely correct that there's a class of constraints that can 
> fail here, but it's not evident to me that dealing with these explicitly 
> when required (in practice, fairly rare) isn't a better tack.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/c7bf261c-bcf6-4903-bc82-49586bc23875%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to