1๐
โ
I am not completely sure about the syntax, but this is how I would write it.
if add_params:
# this piece below feels awkward
for k, v in add_params.copy().iteritems():
if ((v == true) and (role == 'passenger')) # edited the true/false in
or ((v == false) and (role == 'driver')):
add_args.append(Q(**{k: True}) | Q(**{k: False}))
del add_params[k]
elif (type(v) == str) # (x or y) and (x or z) -> x and (y or z)
and ((role == 'passenger') or (role == 'driver')):
add_args.append(Q(**{k: v}) | Q(**{k: u''}))
del add_params[k]
params.update(add_params)
# -----------------------------
return cls.objects.filter(*add_args, **params)[offset:offset + limit]
๐คMathieu Brouwers
Source:stackexchange.com