I will explain it another way: I'm taking as reference the following code http://docs.djangoproject.com/en/dev/ref/forms/validation/ # cleaning- and-validating-fields-that-depend-on-each-other
so my code is as follows: ..... formamig = forms.ModelChoiceField(label = "Tipo de visa", queryset=Formamig.objects.all()) empresa = forms.CharField(max_length=60, required=False) def clean(self): cleaned_data = self.cleaned_data tipo_de_visa = cleaned_data.get("formamig") empresa = cleaned_data.get("empresa") if tipo_de_visa and tipo_de_visa == 'NEGOCIO': msg = u"Debe ingresar el nombre de la empresa." self._errors["tipo_de_visa"] = ErrorList([msg]) self._errors["empresa"] = ErrorList([msg]) del cleaned_data["tipo_de_visa"] del cleaned_data["empresa"] return cleaned_data but not working on my form validation, I think the validation does not work because the field is formamig and example ModelChoiceField fields are Charfield Can you help? On 15 sep, 16:03, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Sep 15, 9:48 pm, alivad <davilani...@gmail.com> wrote: > > > > > hi all: > > > I have the following code: > > > ..... > > formamig = forms.ModelChoiceField(label = "Tipo de visa", > > queryset=Formamig.objects.all()) > > empresa = forms.CharField(max_length=60, required=False) > > > def clean(self): > > cleaned_data = self.cleaned_data > > tipo_de_visa = cleaned_data.get("formamig") > > empresa = cleaned_data.get("empresa") > > > #if tipo_de_visa and "NEGOCIO" in tipo_de_visa: > > if tipo_de_visa and tipo_de_visa == 'NEGOCIO': > > #raise forms.ValidationError("Debe ingresar el nombre de > > la empresa.") > > msg = u"Debe ingresar el nombre de la empresa." > > self._errors["tipo_de_visa"] = ErrorList([msg]) > > self._errors["empresa"] = ErrorList([msg]) > > > # These fields are no longer valid. Remove them from the > > # cleaned data. > > del cleaned_data["tipo_de_visa"] > > del cleaned_data["empresa"] > > > return cleaned_data > > > with the above code I am trying to validate if the user selects > > business then you must place the name of the company. > > > It does not work, someone can help me. > > > Thanks > > What does not work? What happens? > -- > DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---