Creating the views
Before we create the views, we are going to create some helper classes and functions that will make the code in the view simpler and clean. Go ahead and create a file called view_helper.py
in the main app directory, and as usual, let's start by including the import statements:
from rest_framework import generics, status from rest_framework.response import Response from django.http import HttpResponse from .exceptions import InvalidArgumentError from .exceptions import OrderAlreadyCancelledError from .exceptions import OrderAlreadyCompletedError from .serializers import OrderSerializer
Here, we import some things from the Django REST Framework, the main one being the generic, which contains definitions for the generic view classes that we are going to use to create our own custom views. The status contains all the HTTP status codes, which are very useful when sending the response back to the client. Then, we import the Response
class, which will allow us to send content...