podjango: Use or_ instead of lambda

Easier to read.
This commit is contained in:
Ben Sturmfels 2024-02-23 15:00:42 +11:00
parent e7f21fa253
commit ffa2889acb
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0

View file

@ -18,6 +18,7 @@
# #
from datetime import datetime from datetime import datetime
from functools import reduce from functools import reduce
from operator import or_
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.views.generic.list import ListView from django.views.generic.list import ListView
@ -27,7 +28,7 @@ from .models import Cast, CastTag
def OR_filter(field_name, objs): def OR_filter(field_name, objs):
from django.db.models import Q from django.db.models import Q
return reduce(lambda x, y: x | y, return reduce(or_,
[Q(**{field_name: x.id}) for x in objs]) [Q(**{field_name: x.id}) for x in objs])
def last_name(person): def last_name(person):