How can I get computed elements of a table in a django queryset?

后端 未结 5 1653
野的像风
野的像风 2021-01-17 20:53

I\'m trying to use django\'s queryset API to emulate the following query:

SELECT EXTRACT(year FROM chosen_date) AS year, 
EXTRACT(month FROM chosen_date) AS          


        
5条回答
  •  遇见更好的自我
    2021-01-17 21:06

    Just use the raw sql. The raw() manager method can be used to perform raw SQL queries that return model instances.

    https://docs.djangoproject.com/en/1.5/topics/db/sql/#performing-raw-sql-queries

提交回复
热议问题