Am Dienstag, 29. Mai 2007 21:19 schrieb ringemup: > Hello -- > > I'm using a basic form_for_model() form object for a model that has a > unique=True constraint on a field other than the primary key. > > When validating submitted data, is there a reason the form check that > that constraint hasn't been violated and throw a validation error? > I'd like to be able to catch that input error and present a message to > the user, instead of what's currently happening, which is that no > error is thrown and when I try to save the data I get an integrity > error, which is unrecoverable. > > Do I need to create a custom form class just to handle a uniqueness > requirement?
Hi, you can add custom validation methods to the class (either by subclassing or by adding a bound method) Example: ("file" is the attribute of the form/model) def clean_file(self): value = self.fields["file"].widget.value_from_datadict(self.data, self.add_prefix("file")) if not ...: raise forms.ValidationError(u"...") return value --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---