📅  最后修改于: 2022-03-11 14:46:14.192000             🧑  作者: Mango
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.