I'm sorry if this is too basic, just starting on django. How do I call the default clean method? Am I not overriding it by defining on ModelForm?
On Apr 1, 3:35 am, Alex Gaynor <alex.gay...@gmail.com> wrote: > On Tue, Mar 31, 2009 at 10:32 PM, skydark <jedan...@gmail.com> wrote: > > > I am using the clean() method to do some costum validation, but I'm > > getting an exception error instead of the validation error. This does > > not occur when I don't use declare clean(), so I must be missing > > something. > > > #My model > > class Categoria(models.Model): > > nome = models.CharField('nome', max_length=20, unique=True, > > help_text='nome da categoria, limite 20 caracteres') > > > class CategoriaForm(forms.ModelForm): > > class Meta: > > model = Categoria > > > class CategoriaAdmin(admin.ModelAdmin): > > form = CategoriaForm > > > With only this it raises the validation if not unique > > > if I had the following to CategoriaForm I get the exception: > > def clean(self): > > data = self.cleaned_data > > parent = data.get('parent') > > nome_categoria = data.get('nome') > > if parent and nome_categoria: > > if parent.nome == nome_categoria: > > raise forms.ValidationError('A categoria não pode > > pertencer a si mesma. Seleccione Categoria Pai diferente.') > > categoria = Categoria.objects.filter(nome=nome_categoria) > > if categoria: > > subcategoria = categoria[0].subcategorias.filter > > (nome=parent.nome) > > if subcategoria: > > raise forms.ValidationError('A categoria não pode > > pertencer a uma subcategoria de si própria. Seleccione Categoria Pai > > diferente.') > > return self.cleaned_data > > > Help? > > First call the parent class's clean method, then do your own validation. > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---