From 583d4ddfb87c861fb1370b63567ba6f7c2950664 Mon Sep 17 00:00:00 2001 From: imperosol Date: Sun, 10 Nov 2024 15:14:10 +0100 Subject: [PATCH] Use less requests in `GetUserForm.clean` --- counter/forms.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/counter/forms.py b/counter/forms.py index 0945bdb7..84a92512 100644 --- a/counter/forms.py +++ b/counter/forms.py @@ -94,9 +94,13 @@ class GetUserForm(forms.Form): cus = None if cleaned_data["code"] != "": if len(cleaned_data["code"]) == StudentCard.UID_SIZE: - card = StudentCard.objects.filter(uid=cleaned_data["code"]) - if card.exists(): - cus = card.first().customer + card = ( + StudentCard.objects.filter(uid=cleaned_data["code"]) + .select_related("customer") + .first() + ) + if card is not None: + cus = card.customer if cus is None: cus = Customer.objects.filter( account_id__iexact=cleaned_data["code"]