Hi, Suppose you have 2 fields in a query form, both of which are optional. Is there an idiom for building a dictionary to pass into objects.filter() instead of checking the permutations?
eg instead of crazy stuff like this: [[[ if use_sources and use_level: results = NodeEvent.objects.filter( source_time__range=(start_date, end_date), level__exact=level, source__in=sources) elif use_sources and not use_level: results = NodeEvent.objects.filter( source_time__range=(start_date, end_date), source__in=sources) elif not use_sources and use_level: results = NodeEvent.objects.filter( source_time__range=(start_date, end_date), level__exact=level) else: results = NodeEvent.objects.filter( source_time__range=(start_date, end_date) ]]] something like this: [[[ if use_sources: kwargs['sources']= request.GET.getlist('sources') if use_level: kwargs['level'] =request.GET['level'] ... results = NodeEvent.objects.filter(kwargs) ]]] I chanced passing a dictionary straight into objects.filter() as above, (given it has a **kwargs signature), but got this: 'dict' object has no attribute 'get_sql' when the QuerySet was evaluated. cheers Bill --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---