(Disclaimer: tested in Python 2.7, Django 1.6, although it should work at all)
I recently got acquainted with the following construction, which is directly related to the OP problem:
def search(request, val1, val2):
filter_args={}
if val1:
filter_args["first_name"]=val1
if val2:
filter_args["last_name"]=val2
persons = Person.objects.filter(**filter_args)
return persons
, , a-priori, val1, val2. , (and), , , , .filter(...).filter(...) (or). age , , ( val3 ):
if val3:
filter_args["age"]=val3
, , , Django .