Filters can be applied in multiple statements, and querysets are evaluated lazily, so the following would work and would only run a single query, when you finally output or otherwise check the contents of the results variable:
def get_results(...): ... results = MyThing.objects.filter(required_field=somevalue).filter(other_required_field=othervalue) if optional_value_submitted: results = results.filter(optional_field=optional_value) if other_optional_value: results = results.filter(other_optional_field=other_optional_value) return results On Aug 16, 8:20 am, john <deont...@gmail.com> wrote: > hi, > i have a form with few fields as optional,i.e can be left blank, > i want to search my db for values i receive from this form, how should > i go on about writing my filters when some of values can be " ". > any reference is kindly appreciated -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.