Horje
hpw to create related model in django rest framework logic Code Example
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.




Python

Related
factorielle python Code Example factorielle python Code Example
number of words in a string python Code Example number of words in a string python Code Example
change state enabled tkinter Code Example change state enabled tkinter Code Example
pytorch get intersection between two masks Code Example pytorch get intersection between two masks Code Example
return array of sorted objects Code Example return array of sorted objects Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12