python peewee - how to use distinct
Asked Answered
I

1

17

I'm trying to get this code working with peewee:

distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
print distinct_list

but the print command result is:

<class '__main__.QSales'> SELECT DISTINCT t1.`Account`, t1.`Tax_Code` FROM `q_sales` AS t1 WHERE (t1.`Trans_#` = %s) [3717]

running the above select statement in MySQL editor (copy the print result to the editor) returns correct result.

I also tried:

distinct_list = QSales.select(fn.Distinct(QSales.account, QSales.tax_code)).where(QSales.trans_num == 3717)

but got the same result

What am I doing wrong?

Thank you.

Ilocano answered 11/7, 2013 at 15:6 Comment(2)
Can you clarify your post? You pasted in some SQL and the wrote that it returns the "correct result"... if it's correct, what's the problem? If it is incorrect, what exactly are you trying to get?Erinnerinna
Thank you @coleifer. I will edit my question and I also figured out what should I do so I'll include the answer as well.Ilocano
I
25

Sleeping over it, I realized that that code should be as follows:

distinct_list = QSales.select(QSales.account, QSales.tax_code).distinct().where(QSales.trans_num == 3717)
for item in distinct_list:
    print item.account
    print item.tax_code

This is closed now. Thank you.

Ilocano answered 12/7, 2013 at 0:1 Comment(1)
Glad you got it sorted outErinnerinna

© 2022 - 2024 — McMap. All rights reserved.