from django import forms from .models import EmailVerification class EmailVerificationForm(forms.ModelForm): 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