python - Returning a count of grouped items in peewee ORM -


i trying query list on unique field, , count of each unique field using peewee orm. can want mysql workbench, can't seem similar result out of peewee. working mysql query looks this:

select title, severity, count(*) qmodel group title; 

i have tried few variations in peewee nothing has worked. close have gotten:

from application.database.models import qmodel q   _field_select_list = [     q.title,     q.severity,     fn.count(q.title), ]  record in q.select(*_field_select_list).group_by(q.title):    print record 

this returns count, replaces title field on return count, no title ( example {'severity': '3', 'title': '25'})

i made field select this:

_field_select_list = [     q.title,     q.severity,     fn.count(sql('*')), ] 

but gives me grouped list, no count. have tried many other combinations no luck.

have tried leaving count function empty? works fine me on data.

query = q.select(q.title, q.severity, fn.count()).group_by(q.title) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -