While ModelForm.is_valid() finds field validation errors, it cannot
catch errors in uniqueness or referential integrity as far as I can
see. Thus, I have to check them in my view.py code separately
before calling save().
If such errors are detected, I'd like to display them the same way
as the other validation errors are displayed. Is it possible to
inject additional errors into a form? Or are there better ways to
detect and report "inter-form" errors?
Tschö,
Torsten.
--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: torsten...@jabber.rwth-aachen.de
- Andrew Ingram
Andrew Ingram writes:
> ModelForm is really just a convenient subclass of Form, so if you
> want additional validation methods you just have to
> implement/override the clean methods like you would with a normal
> form.
The problem is that at the time the relational integrity checks take
place, the is_valid methods have already been called. Can one call
them multiple times?
Additionally, in order to test e.g. for uniqueness, I need the
complete set of forms which I don't have in a clean() method.
Hallöchen!
While ModelForm.is_valid() finds field validation errors, it cannot
catch errors in uniqueness or referential integrity as far as I can
see. Thus, I have to check them in my view.py code separately
before calling save().
If such errors are detected, I'd like to display them the same way
as the other validation errors are displayed. Is it possible to
inject additional errors into a form? Or are there better ways to
detect and report "inter-form" errors?
Karen Tracey writes:
> On Sun, Jul 13, 2008 at 8:20 AM, Torsten Bronger <
> bro...@physik.rwth-aachen.de> wrote:
>
>> While ModelForm.is_valid() finds field validation errors, it
>> cannot catch errors in uniqueness or referential integrity as far
>> as I can see. Thus, I have to check them in my view.py code
>> separately before calling save().
>>
>> If such errors are detected, I'd like to display them the same
>> way as the other validation errors are displayed. Is it possible
>> to inject additional errors into a form? [...]
>
> Ticket #7444 (http://code.djangoproject.com/ticket/7444) requests
> an official API to support this; [...] I have a feeling this has
> come up a few times and the answer has been "we don't need an
> official API, just access _errors", [...]
As far as I can see, an API is needed at least for Form-level
errors. For example, if a Pizza should have at least one Topping
(many-to-one relationship, I'd like to tell the user about it. But
this is certainly not associated with any field.