Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django expressionwrapper example

from django.db.models import F, Avg, Value, FloatField, ExpressionWrapper
from django.db.models.functions.comparison import NullIf

context['stock_margin'] = context['top_stock'].annotate(
    Avg_purchase = ExpressionWrapper(
        F('total_puchase') / NullIf(F('quantity_purchase'), 0),
        output_field=FloatField()
    ),
    Avg_sales = ExpressionWrapper(
        F('total') / NullIf(F('quantity'), 0),
        output_field=FloatField()
    )
)
Comment

PREVIOUS NEXT
Code Example
Python :: python game over screen 
Python :: schedule asyncio python 
Python :: python loop certain number of times 
Python :: how to get user ip in python 
Python :: create a vector of zeros in r 
Python :: python get everything between two characters 
Python :: kill turtle 
Python :: pygame.set_volume(2.0) max volume 
Python :: python datetime subtract seconds 
Python :: python selenium assert presence of an element 
Python :: How to Create a Pie Chart in Seaborn 
Python :: python sort 2d list 
Python :: skip rows in pandas read excel 
Python :: values of unique from dataframe with count 
Python :: python datetime into 12-hour format 
Python :: how to get width of an object in pyqt5 
Python :: python async threading 
Python :: python convert hex to binary 
Python :: import a txt file into python 
Python :: multivariate outlier detection python 
Python :: python filter a dictionary 
Python :: how to subtract dates in python 
Python :: for loop with zip and enumerate 
Python :: numpy print options 
Python :: how to print all combinations of a string in python 
Python :: pandas reorder columns 
Python :: python thread with parameters 
Python :: delete the duplicates in python 
Python :: pandas how to start read csv at a certain row 
Python :: use of // in python 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =