from django import forms from django_recaptcha.fields import ReCaptchaField from django_recaptcha.widgets import ReCaptchaV3 from .models import EmailVerification class EmailVerificationForm(forms.ModelForm): captcha = ReCaptchaField(widget=ReCaptchaV3()) class Meta: model = EmailVerification fields = ["email"] def clean_email(self): email = self.cleaned_data.get("email") if EmailVerification.objects.filter(email=email).exists(): raise forms.ValidationError("This email address is already in use.") return email