Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Group by date (day, month, year)

from django.db.models.functions import TruncMonth
from django.db.models import Count

Sales.objects
    .annotate(month=TruncMonth('created'))  # Truncate to month and add to select list
    .values('month')                          # Group By month
    .annotate(c=Count('id'))                  # Select the count of the grouping
    .values('month', 'c')                     # (might be redundant, haven't tested) select month and count
Comment

PREVIOUS NEXT
Code Example
Python :: Jupyter to access jupyter notebook on virtualbox guest through browser in windows host 
Python :: python laplace expansion 
Python :: manipulate list using slice assignment 
Python :: # find the n smallest and greatest numbers in list 
Python :: flask crud generator 
Python :: quadkey calculator 
Python :: get dataframe deminsions 
Python :: Linear Search Python with enumerate 
Python :: pyton 
Python :: change xlabel size 
Python :: use dict to replace missing values pandas 
Python :: range function without end value 
Python :: Code example of Python Modulo Operator with Exception handling 
Python :: Convert Int to String Using F-strings 
Python :: Example of Python Strings with indexing 
Python :: python create named timer 
Python :: print using multiply only 
Python :: travers a list 
Python :: python sumproduct excel 
Python :: python new set 
Python :: Broadcasting with NumPy Arrays Example 
Python :: how to shuffle list in djnago 
Python :: Python NumPy asanyarray Function Syntax 
Python :: Python NumPy array_split Function Example 02 
Python :: SciPy KDTrees 
Python :: Python how to use __ne__ 
Python :: python multiply function with return keyword 
Python :: django view - mixins and GenericAPIView (retrieve, update or delete - GET, PUT, DELETE) 
Python :: python mysqldb sockets 
Python :: extract numbers from image python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =