The DestroyAPIView is a subclass or interface for deleting model instances from the database through the REST API. In this video, learn how to create a subclass of DestroyAPIView that deletes and removes a shopping cart item model from the database.
- We can list products, and create them, … but what about if we want to delete products … from the database? … We can use the generic view DestroyAPIView … to create an API for that. … We import it, … and then we create our DestroyView. … We set the queryset to All Products … and the lookup_field to id. … There isn't much to creating an API View … to destroy an object. … We just need to set the queryset and the lookup field. … In a real world situation, however, … a product being destroyed may also mean … that all caches that store data related to that product … have to be cleared. … Clearing the cache when a model is destroyed … frees up cache space for other objects … that are more likely to be used. … Let's see how that looks. … We override the delete method, … we extract the product_id from the request, … we proceed with deleting the object, … and if the product was deleted successfully, … we're going to import the django.cache … and delete the product_data from the cache. … Then we just return to response, as per usual, …
- Creating a serializer
- Working with API views
- Filtering back ends
- Enabling pagination
- Executing CRUD operations
- Managing serializer fields
- Testing API views
Skill Level Intermediate
Deploying Django Apps: Make Your Site Go Livewith Nick Walter2h 43m Intermediate
Demo project overview1m 19s
1. Serializing, Listing, Filtering, and Paginating Models
2. Create, Retrieve, Update, and Delete (CRUD) Operations for Models
3. Managing Serializer Fields, Relations, and Validation
4. Testing API Views
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.