Incorrect SQL generated for OVER clause
Instead of using `.challenge_id` can you use `.challenge` instead? Let me know. PS I had to reformat your code so I could read it without scrolling -- please add linebreaks for long chunks of code.
 Closing. Please reopen if this does not address your concern.
 Thanks! Stupid mistake by me. Using `.challenge` instead of `.challenge_id` worked perfectly.
 Not stupid at all, glad that helped.

I'm trying to implement sub ordering on my table based on the `challenge_id`field using the following peewee query:

``` python
(ChallengeResult
 .select(
   ChallengeResult, 
   fn.row_number().over(
     partition_by=[ChallengeResult.challenge_id], 
     order_by=[ChallengeResult.length.desc()]).alias("row_number"))
 .where(ChallengeResult.user == user).alias("rows"))
```

This should generate the following SQL:

``` sql
('
SELECT "t1"."id", "t1"."created_at", "t1"."user_id", "t1"."challenge_id", "t1"."length", 
  row_number() OVER (
    PARTITION BY "t1"."challenge_id" 
    ORDER BY "t1"."length" DESC) AS row_number FROM "challenge_result" AS t1 
WHERE ("t1"."user_id" = %s)', [2])
```

and return these results:

```
 id  |         created_at         | user_id | challenge_id | length | row_number 
-----+----------------------------+---------+--------------+--------+------------
 149 | 2016-01-12 08:45:30.534326 |       2 |            2 |    200 |          1
 151 | 2016-01-12 08:57:27.233171 |       2 |           11 |    101 |          1
 150 | 2016-01-12 08:57:21.597426 |       2 |           11 |    100 |          2
```

For some reason the `PARTITION BY` clause in the `OVER` clause is missing the table field and the generated SQL looks like:

``` sql
('
SELECT "t1"."id", "t1"."created_at", "t1"."user_id", "t1"."challenge_id", "t1"."length", 
  row_number() OVER (
    PARTITION BY %s 
    ORDER BY "t1"."length" DESC) AS row_number FROM "challenge_result" AS t1 
WHERE ("t1"."user_id" = %s)', [None, 2])
```

Returning these results:

```
 id  |         created_at         | user_id | challenge_id | length | row_number 
-----+----------------------------+---------+--------------+--------+------------
 149 | 2016-01-12 08:45:30.534326 |       2 |            2 |    200 |          1
 151 | 2016-01-12 08:57:27.233171 |       2 |           11 |    101 |          2
 150 | 2016-01-12 08:57:21.597426 |       2 |           11 |    100 |          3
```

Using peewee 2.7.4, python 3.4.0 and postgresql 9.3.9.
