agency unique email contraint fail solved
This commit is contained in:
parent
2211c5f3b2
commit
227a48b285
@ -27,7 +27,8 @@ from .models import (
|
|||||||
Participants,
|
Participants,
|
||||||
Message,
|
Message,
|
||||||
Person,
|
Person,
|
||||||
Document
|
Document,
|
||||||
|
CustomUser
|
||||||
)
|
)
|
||||||
|
|
||||||
# from django_summernote.widgets import SummernoteWidget
|
# from django_summernote.widgets import SummernoteWidget
|
||||||
@ -1028,17 +1029,20 @@ class HiringAgencyForm(forms.ModelForm):
|
|||||||
raise ValidationError("Please enter a valid email address.")
|
raise ValidationError("Please enter a valid email address.")
|
||||||
|
|
||||||
# Check uniqueness (optional - remove if multiple agencies can have same email)
|
# Check uniqueness (optional - remove if multiple agencies can have same email)
|
||||||
instance = self.instance
|
# instance = self.instance
|
||||||
if not instance.pk: # Creating new instance
|
email = email.lower().strip()
|
||||||
if HiringAgency.objects.filter(email=email).exists():
|
if CustomUser.objects.filter(email=email).exists():
|
||||||
raise ValidationError("An agency with this email already exists.")
|
raise ValidationError("This email is already associated with a user account.")
|
||||||
else: # Editing existing instance
|
# if not instance.pk: # Creating new instance
|
||||||
if (
|
# if HiringAgency.objects.filter(email=email).exists():
|
||||||
HiringAgency.objects.filter(email=email)
|
# raise ValidationError("An agency with this email already exists.")
|
||||||
.exclude(pk=instance.pk)
|
# else: # Editing existing instance
|
||||||
.exists()
|
# if (
|
||||||
):
|
# HiringAgency.objects.filter(email=email)
|
||||||
raise ValidationError("An agency with this email already exists.")
|
# .exclude(pk=instance.pk)
|
||||||
|
# .exists()
|
||||||
|
# ):
|
||||||
|
# raise ValidationError("An agency with this email already exists.")
|
||||||
return email.lower().strip() if email else email
|
return email.lower().strip() if email else email
|
||||||
|
|
||||||
def clean_phone(self):
|
def clean_phone(self):
|
||||||
|
|||||||
@ -3313,6 +3313,7 @@ def agency_create(request):
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = HiringAgencyForm(request.POST)
|
form = HiringAgencyForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
||||||
agency = form.save()
|
agency = form.save()
|
||||||
messages.success(request, f'Agency "{agency.name}" created successfully!')
|
messages.success(request, f'Agency "{agency.name}" created successfully!')
|
||||||
return redirect("agency_detail", slug=agency.slug)
|
return redirect("agency_detail", slug=agency.slug)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user