Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Return monthly sales value in Django

from django.db.models import Sum, F, FloatField
from django.db.models.functions import ExtractMonth

output = (
    Order.objects
    .annotate(
        month=ExtractMonth("created")
    )
    .values("month")
    .annotate(
        count=Sum("products__quantity"),
        total=Sum(
            F("products__quantity") * F("products__product__price"),
            output_field=FloatField()
        )
    )
    .order_by("month")
)
Comment

PREVIOUS NEXT
Code Example
Python :: .format() multiple placeholders 
Python :: How to avoit print() to go to newline each time 
Python :: python access class property from string 
Python :: flask crud generator 
Python :: evaluacion PCA python 
Python :: for i in range(1, 11): print(i, end="") 
Python :: double except python 
Python :: how call a class in another class python 
Python :: python bitcoin prices 
Python :: get ggplot colorpalette python 
Python :: pyttsx3 interrupting an utterance 
Python :: pydantic array of objects 
Python :: Example pandas.read_hdf5() 
Python :: Using Python Permutations function on a String with extra parameter 
Python :: foreach on sysargv 
Python :: unique character 03 set and length comparison 
Python :: python swap two numbers 
Python :: how to move mouse by detected face and eye using opencv 
Python :: OSError Traceback (most recent call last) <ipython-input-74-8920269c5588 in <module() 9 10 run_with_ngrok(app) --- 11 app.run() 
Python :: how to dinamically create the Q query in django 
Python :: Python NumPy atleast_1d Function Example 
Python :: brython sample 
Python :: Python NumPy asfortranarray Function Example array to fortanarray 
Python :: inverrt heatmap cmap 
Python :: (ax=self.canv.axes ,style="ro--") 
Python :: python model feature importance 
Python :: scipy kullbach leibler divergence 
Python :: ax bar different colors 
Python :: complete dates pandas per group by 
Python :: numpy extract decimal 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =