Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- month = InfraVltgDetail.objects.annotate(
- month=TruncMonth('create_dt'))
- .values('month').annotate(
- name_count=Count('id'))
- .values('month', 'name_count')
- #print(by_month.query)
- output:
- SELECT django_datetime_trunc('month', "portal_infravltgdetail"."create_dt", 'UTC')
- AS "month", COUNT("portal_infravltgdetail"."id")
- AS "name_count" FROM "portal_infravltgdetail"
- GROUP BY django_datetime_trunc('month', "portal_infravltgdetail"."create_dt", 'UTC')
- import psycopg2
- conn = psycopg2.connect(database="test",
- user = "postgres",
- password = "postgres",
- host = "localhost",
- port = "5432")
- cur = conn.cursor()
- cur.execute(output_query)
- cur.fetchall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement