Answers for "hpw to create related model in django rest framework logic"

0

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.
Posted by: Guest on August-20-2020

Code answers related to "hpw to create related model in django rest framework logic"

Python Answers by Framework

Browse Popular Code Answers by Language