Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django orm group by month and year

print([v for v in
       Request.objects.annotate(month=ExtractMonth('date_creation'),
                                year=ExtractYear('date_creation'),)
                      .order_by()
                      .values('month', 'year')
                      .annotate(total=Count('*'))
                      .values('month', 'year', 'total')
       ])
Comment

Django: Group by date (day, month, year)

from django.db.models.functions import ExtractMonth
Sales.objects
    .annotate(month=ExtractMonth('timestamp')) 
    .values('month')                          
    .annotate(count=Count('id'))                  
    .values('month', 'count')
Comment

PREVIOUS NEXT
Code Example
Python :: flask dockerize 
Python :: smtp python set subject 
Python :: enable time layer arcpy 
Python :: hover show all Y values in Bokeh 
Python :: merge pandas datasets 
Python :: python dictionary pop 
Python :: how to get the index of the first integer in a string python 
Python :: how to input n space separated integers in python 
Python :: Converting Dataframe from the multi-dimensional list with column name 
Python :: np.tanh 
Python :: Publish Image msg ros python 
Python :: win64pyinstaller 
Python :: last element of list python 
Python :: how to remove some characters from a string in python 
Python :: python sleep 
Python :: up and down arrow matplotlib 
Python :: nltk bigrams 
Python :: shallow copy in python 
Python :: train dev test split sklearn 
Python :: concat dataframe pandas 
Python :: python list replace nan with 0 
Python :: spanish to english 
Python :: install fastapi 
Python :: convert list to string separated by comma python 
Python :: list all files in folder python 
Python :: df sort by column names 
Python :: python read file xlsx and return a list 
Python :: pandas nat to null? 
Python :: create virtualenv python3 
Python :: nested loop 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =