DestroyAPIView is a view class in Django Rest Framework that provides the functionality to handle HTTP DELETE requests. This video shows how I'm implementing the DestroyAPIView class in my Social Scheduler app to delete the connected social accounts.
Gist URL: https://gist.github.com/InterTuts/e99900298605865b899410a8eb07acec
Gist URL: https://gist.github.com/InterTuts/e99900298605865b899410a8eb07acec
Category
🦄
CreativityTranscript
00:00In this video, I want to show how to delete data from a database using Django REST framework.
00:12For example, here I'm deleting the social accounts.
00:19When I click on the delete button, I'm using the click trigger to trigger this function with account ID.
00:43Here I'm using the account ID in the URL and I'm sending a request to the API.
00:58And here I have the receiver for this request, where I'm receiving the ID.
01:26This class handles the deletion requests and I'm implementing the DestroyAPIView class
01:42to leverage the specialized functionalities of Django REST framework for deletion.
01:53In this class, I won't use Serializer or QuerySet.
02:10I'm using the networks model because I want to delete the social accounts from this database.
02:24Next, I'm using this for authentication because only an authentication user can delete a social account.
02:37Next, I'm using or I'm getting the ID from here.
02:47And I'm applying it to the QuerySet and I'm using even the authenticated user to get only its accounts
03:12because the user can delete only its social accounts.
03:19Here I'm verifying if the account exists by ID.
03:28And then I'm deleting the social account.
03:34In this way works the code for the social accounts deletion showed at the beginning of this video.