Saturday, July 2, 2016

Re: IntegrityError column email is not unique

@James

As per my understanding I did following. Now it is not adding email if it exists but also its not giving me any error.

class GuestCheckoutForm(forms.Form):
    email = forms.EmailField()
    email2 = forms.EmailField(label='Verify Email')

    def clean_email(self):
        email = self.cleaned_data["email"]
        if UserCheckout.objects.filter(email=email).exists():
            raise forms.ValidationError("Please confirm emails addresses are the same.")
        return email

    def clean(self):
        cleaned_data = super(GuestCheckoutForm, self).clean()
        email = cleaned_data.get('email')
        email2 = cleaned_data.get('email2')

        if email and email2 and email != email2:
            self.add_error('email2', forms.ValidationError('Please confirm emails addresses.'))

Rest of the code is same.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12116f4b-01b5-4a33-9397-20819d11557d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment