I want to have an email check in my email form field so that if the user's email doesn't end with '@aun.edu.ng' it will through an error message.
forms.py
class EmployeeRegistrationForm(forms.ModelForm):
first_name = forms.CharField(label='First Name')
last_name = forms.CharField(label='Last Name')
cv = forms.FileField(label='CV')
skills_or_trainings = forms.SlugField(label='Skills or Trainings', required=False, widget=forms.Textarea)
class Meta:
model = Student
fields = ['first_name', 'last_name', 'gender', 'level', 'school', 'major', 'cv', 'skills_or_trainings' ]
class EmployerRegistrationForm(forms.ModelForm):
company_name = forms.CharField(label="Company Name")
company_address = forms.CharField(label="Company Address")
website = forms.CharField()
class Meta:
model = Employer
fields = ['company_name', 'company_address', 'website']
views.py
def student_register(request):
if request.method == 'POST':
form = UserRegistrationForm(request.POST)
student_form = EmployeeRegistrationForm(request.POST)
if form.is_valid() and student_form.is_valid():
user = form.save(commit=False)
user.is_student = True
user.save()
student = student_form.save(commit=False)
student.user = user
student.save()
return redirect('login')
else:
form = UserRegistrationForm()
student_form = EmployeeRegistrationForm()
context = {'form': form, 'student_form': student_form}
return render (request, 'accounts/employee/register.html', context)
def employer_register(request):
if request.method == 'POST':
form = UserRegistrationForm(request.POST)
employer_form = EmployerRegistrationForm(request.POST)
if form.is_valid() and employer_form.is_valid():
user = form.save(commit=False)
user.is_employer = True
user.save()
employer = employer_form.save(commit=False)
employer.user = user
employer.save()
return redirect('login')
else:
form = UserRegistrationForm()
employer_form = EmployerRegistrationForm()
context = {'form': form, 'employer_form': employer_form}
return render (request, 'accounts/employer/register.html', context)
Please how do I go about it so that I will be able to through a Validation Error message when the user puts in an email that doesn't end with '@aun.edu.ng' Thank you