coleifer/peewee — pull request #101 by ternus (2012-07-13 23:33:13+00:00)
Title: Multiple annotation using different aggregates fails

Using .annotate() multiple times on the same query fails:

```python
annotated = Blog.select().annotate(Entry).annotate(Entry, Max('pub_date', 'max_pub'))
```
generates the SQL:
```sql
SELECT t1."id", t1."title", MAX(t2."pub_date") AS max_pub FROM "blog" AS t1 INNER JOIN "entry" AS t2 ON t1."id" = t2."blog_id" GROUP BY t1."id", t1."title", *
```
which is a syntax error (stray * near the end) in addition to being wrong. The SQL generated should be something like:
```sql
SELECT t1."id", t1."title", COUNT(t2.`pk`) AS count, MAX(t2."pub_date") AS max_pub FROM "blog" AS t1 INNER JOIN "entry" AS t2 ON t1."id" = t2."blog_id" GROUP BY t1."id", t1."title"
```

I've added a failing test for this case.