how to add business logic to django rest framework code example
Example 1: django rest framework business logic
def order(request, quantity=1):
order_id = CoffeeShopService.place_order(quantity)
return HttpResponse({'order_id': order_id, mimetype='application/json')
Example 2: django rest framework business logic
class CoffeeShopService(object):
@staticmethod
def place_order(quantity):
return order_id
Example 3: 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):
def calculate_tax(self, whatever_params):
def calculate_grand_total(self, whatever_params):
def create(self, validated_data):