coordt/django-alphabetfilter — pull request #9 by shagi (2012-12-05 21:48:07+00:00)
Title: Use django querysets to fetch available letters

Using raw SQL on the model table doesn't work on inherited models. For example:

```
class Worker(models.Model):
name = models.CharField(max_lenght=100)

class Technician(Worker):
description = models.TextField()
```

With this models alphafilter can't filter the technicians by their name.

Using django querysets (and a custom aggregation function) all necessary
table joins are made, and the executed SQL is not much worse:

For worker filtering:
```
'SELECT DISTINCT UPPER(SUBSTR("sample_worker"."name", 1, 1)) AS "fl" FROM "sample_worker" GROUP BY "sample_worker"."name"'
```

For Technician filtering:

```
'SELECT DISTINCT UPPER(SUBSTR("sample_worker"."title", 1, 1)) AS "fl" FROM "sample_technician" LEFT OUTER JOIN "sample_worker" ON ("sample_technician"."building_ptr_id" = "sample_worker"."id") GROUP BY "sample_worker"."title"'
```

Another benefit of this approach is that custom querysets can be used, to
get filtering on a subset of the table.