From e1b6611385f44a47bdd9fea64972cd290bfa0438 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Wed, 7 Aug 2024 09:02:56 +0000 Subject: [PATCH] feedback --- codeforlife/user/filters/user.py | 6 ++++-- codeforlife/user/models/teacher.py | 9 ++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/codeforlife/user/filters/user.py b/codeforlife/user/filters/user.py index af9550d1..a9ccde61 100644 --- a/codeforlife/user/filters/user.py +++ b/codeforlife/user/filters/user.py @@ -5,6 +5,7 @@ import typing as t +from django.db.models import Q # isort: skip from django.db.models.query import QuerySet # isort: skip from django_filters import ( # type: ignore[import-untyped] # isort: skip rest_framework as filters, @@ -40,8 +41,9 @@ def name_method( # TODO: use PostgreSQL specific lookup # https://docs.djangoproject.com/en/5.0/ref/contrib/postgres/lookups/#std-fieldlookup-trigram_similar return queryset.filter( - first_name__icontains=first_name - ) | queryset.filter(last_name__icontains=last_name) + Q(first_name__icontains=first_name) + | Q(last_name__icontains=last_name) + ) def only_teachers__method( self: FilterSet, queryset: QuerySet[User], _: str, value: bool diff --git a/codeforlife/user/models/teacher.py b/codeforlife/user/models/teacher.py index f100d3ce..0b816a8e 100644 --- a/codeforlife/user/models/teacher.py +++ b/codeforlife/user/models/teacher.py @@ -9,6 +9,7 @@ from common.models import Teacher, TeacherModelManager from django.db import models +from django.db.models import Q from .klass import Class from .school import School @@ -100,9 +101,8 @@ def school_users(self): # pylint: disable-next=import-outside-toplevel from .user import User - return ( - # student-users - User.objects.filter( + return User.objects.filter( + Q( # student-users new_teacher__isnull=True, **( {"new_student__class_field__teacher__school": self.school} @@ -110,8 +110,7 @@ def school_users(self): else {"new_student__class_field__teacher": self} ) ) - # school-teacher-users - | User.objects.filter( + | Q( # school-teacher-users new_student__isnull=True, new_teacher__school=self.school, )