<p>Given a class:</p>

<pre><code>from django.db import models

class Person(models.Model):
    name = models.CharField(max_length=20)
</code></pre>

<p>Is it possible, and if so how, to have a QuerySet that filters based on dynamic arguments?  For example:</p>

<pre><code> # Instead of:
 Person.objects.filter(name__startswith='B')
 # ... and:
 Person.objects.filter(name__endswith='B')

 # ... is there some way, given:
 filter_by = '{0}__{1}'.format('name', 'startswith')
 filter_value = 'B'

 # ... that you can run the equivalent of this?
 Person.objects.filter(filter_by=filter_value)
 # ... which will throw an exception, since `filter_by` is not
 # an attribute of `Person`.
</code></pre>

A really complex search forms usually indicates that a simpler model is trying to dig it's way out.
How, exactly, do you expect to get the values for the column name and operation?
Where do you get the values of
```
'name'
```
an
```
'startswith'
```
?
```
```
filter_by = '%s__%s' % ('name', 'startswith')
```
```
A "search" form?  You're going to -- what? -- pick the name from a list of names?  Pick the operation from a list of operations?  While open-ended, most people find this confusing and hard-to-use.
How many columns have such filters? 6? 12? 18?
A few?  A complex pick-list doesn't make sense.  A few fields and a few if-statements make sense.
A large number?  Your model doesn't sound right.  It sounds like the "field" is actually  a key to a row in another table, not a column.
Specific filter buttons.  Wait... That's the way the Django admin works.  Specific filters are turned into buttons.  And the same analysis as above applies.  A few filters make sense.  A large number of filters usually means a kind of first normal form violation.
A lot of similar fields often means there should have been more rows and fewer fields.