Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Aug 7, 2024
1 parent deae2ba commit e1b6611
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions codeforlife/user/filters/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions codeforlife/user/models/teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,18 +101,16 @@ 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}
if self.is_admin
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,
)
Expand Down

0 comments on commit e1b6611

Please sign in to comment.