hello Pals,
i have form add unit with validation for valid form and inside valid i have other validation if the object already inside database. but it always get out of the second validation,
it work with add new but when i try add obj already there it break out of the valid validation.
else:
messages.error(
request,
f"({name}) failed, already exists",
)
This Code Never reach it.
def add_unit_names(request):
lst = Lst.objects.all()
if request.method == "POST":
frm = LstFrm(request.POST or None)
if frm.is_valid():
sv_frm = frm.save(commit=False)
name = request.POST.get("name")
match = UnitNames.objects.filter(name=name).exists()
if not match:
sv_frm.save()
name = sv_frm.name
id = sv_frm.id
messages.success(request, f"({name}) created successfully.")
return redirect(reverse("home", args=(id,)))
else:
messages.error(
request,
f"({name}) failed, already exists",
)
else:
messages.error(
request,
"Please fill in the form with valid data.",
)
frm = LstFrm()
else:
frm = LstFrm()