diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-05 17:42:08 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-05 17:42:08 +0000 |
commit | 30101453a75aaa635e3458d509dec164a6a68ac1 (patch) | |
tree | ceb332bad155a7abe037acc9c123a0bf42dd9ec7 /alphabetlearning/payments/forms.py | |
parent | 7cd2fd2b75bc5597e9b2a128bf61201910be6df2 (diff) |
Add unique constraint to EmailVerification email field
This update enhances the EmailVerification model by ensuring the email field is unique, preventing duplicate records. A new form, EmailVerificationForm, was also introduced to handle email cleaning and validation, which enhances user input handling. Additionally, existing views and templates have been updated to integrate this form, improving the user experience and error feedback.
Diffstat (limited to 'alphabetlearning/payments/forms.py')
-rw-r--r-- | alphabetlearning/payments/forms.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/alphabetlearning/payments/forms.py b/alphabetlearning/payments/forms.py new file mode 100644 index 0000000..f69397f --- /dev/null +++ b/alphabetlearning/payments/forms.py @@ -0,0 +1,14 @@ +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
\ No newline at end of file |