Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

hpw to create related model in django rest framework logic

class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = Order
        fields = (
            'id',
            'total',
            'discount',
        )

    def calculate_discount(self, whatever_params):
        # calculate discount if you need... and return it

    def calculate_tax(self, whatever_params):
        # calculate tax amount if you need...and return it

    def calculate_grand_total(self, whatever_params):
        # calculate grand total if you need and return it

    def create(self, validated_data):
        # You can make an order by applying 
        # some logic in the calculation method.
        # Maybe by adding a bit of the context 
        # you sent as parameters from view.
Comment

PREVIOUS NEXT
Code Example
Python :: exec inside def is not working in python 
Python :: comment enleve les chiffre duplice d une liste python 
Python :: gdal user with anaconda 
Python :: the process of delivery of any desisered data 
Python :: python how to get variable value in dict 
Python :: use of numpy matrix in tkinter python 3 
Python :: jupyter_ascending 
Python :: pandas condense dataframe by summing according to ID 
Python :: combine int and object columns into one 
Python :: how to sort variable in specifiic order in python 
Python :: python fibonacci numbers 
Python :: fibonacci sequence in python 2.7 
Python :: starting python project 
Python :: differentate derivative differentation 
Python :: RuntimeError: cuda runtime error (711) : peer mapping resources exhausted at /pytorch/aten/src/THC/THCGeneral.cpp:139 
Python :: how to add another timestamp column plus two hours 
Python :: Form rendering options in django 
Python :: How to make boxplot using seaborne 
Python :: how to code discord bot 8ball python 
Python :: check firebase email 
Python :: for_else_and_while_else_statement 
Python :: calculated fields in models 
Python :: # to check if the list is empty use len(l) or not 
Python :: python discord bot create role 
Python :: program to add two numbers in python 
Python :: print numbers 1 to 10 using recursion in python 
Python :: Flatten List in Python Using Shallow Flattening 
Python :: cubic interpolation python 
Python :: python comment faire une boucle 
Python :: *9c0xxbz] 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =