15

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.

yunandtidus
  • 3,847
  • 3
  • 29
  • 42
Erans
  • 401
  • 1
  • 5
  • 11
  • 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? – coleifer Jul 11 '13 at 18:46
  • 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. – Erans Jul 11 '13 at 23:52

1 Answers1

21

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.

Erans
  • 401
  • 1
  • 5
  • 11