Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

case statement in querset django

# Creating a calculated column named 'discount' on Client table 
# Using conditional case statement with nested When -> Then logic
Client.objects.annotate(
     discount=Case(
         When(account_type=Client.GOLD, then=Value('5%')),
         When(account_type=Client.PLATINUM, then=Value('10%')),
         default=Value('0%'),
     ),
 ).values_list('name', 'discount')
Comment

PREVIOUS NEXT
Code Example
Python :: import django-on-heroku 
Python :: printing float number python 
Python :: python input lowercase 
Python :: select specific rows from dataframe in python 
Python :: remove all whitespace from string python 
Python :: pytorch view -1 meaning 
Python :: how to do element wise multiplication in numpy 
Python :: pandas str is in list 
Python :: Python make directories recursively 
Python :: Installing packages from requirements.txt file 
Python :: find columns with missing values pandas 
Python :: how to change background of tkinter window 
Python :: python copy object 
Python :: python regex get all matches 
Python :: create fixtures django 
Python :: how to create empty series in pandas 
Python :: pandas replace colomns location 
Python :: pandas difference between dates 
Python :: pandas groupby aggregate multiple columns 
Python :: pandas dataframe delete column 
Python :: python instagram downloader 
Python :: mac why is python installed in usr and application 
Python :: Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming 
Python :: python Non-UTF-8 code starting with 
Python :: orderd set in python 
Python :: pyqt5 image 
Python :: how to check if a list is a subset of another list 
Python :: how to combine two arrays in python 
Python :: pandas not in list 
Python :: how to add an item to a list in python 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =