From the course: Building RESTful Web APIs with Django

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating an UpdateAPIView subclass

Creating an UpdateAPIView subclass

From the course: Building RESTful Web APIs with Django

Start my 1-month free trial

Creating an UpdateAPIView subclass

- [Narrator] Right now we can delete individual products. That happens through the DestroyAPIView, but what if we wanted to retrieve an individual product's data? We would have to create a new RetrieveAPIView to handle the Get HTTP method. And what if we also wanted to update and individual products data, whether fully updating it or partially updating it? We would again have to create another APIView this time using UpdateAPIView. But why do all of that when we can just use Django rest frameworks generic view that combines all of those. With the RetrieveUpdateDestroyAPIView we cam reuse code and configuration. For example, the serialiszer_class or queryset and other configuration options for generic views. And on top of that we can use One URL to handle multiple HTTP methods. To allow for this combination of actions we're going to re-factor the ProductDestroyAPIView into the RetrieveUPdateDestroyAPIView. We need to import it (typing) and then re-factor the ProductDestroy class. We…

Contents