Django filter query if filter parameter exists
问题 I'm trying to create a django filter with multiple filter parameters (ex. name, age, height). However, I only want to filter by a parameter if it exists... In my init: def __init__(self, name=None, age=None, height=None): self.name = name self.age = age self.height = height in my query: Person.objects.filter(name=self.name, age=self.age, height=self.height) However, the problem is since the parameters are optional in the constructor, there is a chance that the filter is looking for None