Resolved. In this method:
formset_funcionario = modelformset_factory (Funcionario,formset=func_set,max_num=7,extra=1) Django seems to create a new class dinamycally called: [name_of_model] Form In the case above, tha class created would be: django.forms.models.FuncionarioForm If I want that the validation of each form in the formset respects a validation of a one Form especifically, I have to pass the class of this Form in the method modelformset_factory. formset_funcionario = modelformset_factory (Funcionario,form=FuncionarioForm,formset=func_set,max_num=7,extra=1) This way, when I call the method is_valid() from formset_funcionario, the validation methods of the Form FormFuncionario will be executed. On 15 jul, 11:54, danielA <danoan2...@gmail.com> wrote: > I have a Model; > > class Funcionario(models.Model): > nome = models.CharField(max_length=200) > email = models.CharField(max_length=100) > data_nasc = models.DateField('Data de Nascimento') > salario = models.FloatField() > observacao = models.CharField(max_length=500) > > I have a ModelForm for this Model > > class FuncionarioForm(ModelForm): > email = MyEmailField() > > class Meta: > model = Funcionario > > def clean_email(self): > data = self.cleaned_data['email'] > > if data != 'meuem...@gmail.com': > raise forms.ValidationError("ops, cleanEmail") > > return data > > And I have a FormSet for this same Model > > class FuncionarioFormSet(BaseModelFormSet): > def __init__(self, *args, **kwargs): > self.queryset = Funcionario.objects.all() > super(FuncionarioFormSet, self).__init__(*args, **kwargs) > > Validation for the ModelForm goes fine: > > When I call the is_valid() method from FuncionarioForm > django does: > > 1. First calls the clean() method of each Field. > 2. Calls the clean_email() method on FuncionarioForm > 3. Call the clean() method on FuncionarioForm > > What I want it´s that steps above be repeated on validation of > FuncionarioFormSet. > > Django actually does this according my code: > > When I call the is_valid() method from FuncionarioFormSet > Django does: > > 1. Calls the clean() method of each Field. > 2. Call the clean() method of FuncionarioFormSet. > > It´s possible create clean_field methods for the validation of a > ModelFormSet? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---