You don't have to write all the filter statements at once, you can add
them incrementally. I usually do this kind of thing like:

var1 = request.GET.get('var1', None)
var2 = request.GET.get('var2', None)
var3 = request.GET.get('var3', None)
object_list = MyModel.objects.all()
if var1:
    object_list = object_list.filter(var1=var1)
if var2:
    object_list = object_list.filter(var2=var2)
if var3:
    object_list = object_list.filter(var3=var3)

But I'm usually not dealing with 12 variables (and I often do more than
filter in each if block), so you might want to go with something more
clever if that's too much typing for your case. Just off the top of my
head (untested!):

object_list = MyModel.objects.all()
for key, value in request.GET.items():
    if value:
        object_list = object_list.filter(**{key: value})


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to