1👍
✅
Use **kwargs
in your function definition and filter out None
valued items using a dictionary comprehension before passing and unpacking the named arguments to filter
:
def search(**kwargs):
kwargs = {k: v for k, v in kwargs.items() if v}
queryset = Organization.objects.filter(**kwargs)
return queryset
Source:stackexchange.com