0

I am trying to override delete method in generics.RetrieveUpdateDestroyAPIView class using the followings code snippet. :-

In views.py

class ArtistView(generics.RetrieveUpdateDestroyAPIView):
    serializer_class = ArtistSerializer
    queryset = Users.objects.filter(user_type='artist')

In serializers.py

class ArtistProfileSerializer(serializers.ModelSerializer):

    class Meta:
        model = Profile
        fields = ('profile_pic_url','cover_pic_url','full_name','genre','location')


class ArtistSerializer(serializers.ModelSerializer):

    profiles = ArtistProfileSerializer(many=False)

    class Meta:
        model = Users
        fields =  ['id','user_type', 'email', 'profiles','username']
        def delete(self, instance, *arg, **kwargs):
            profile = instance.profiles
            profile.delete()

In urls.py

urlpatterns = [
path('all-artist/', views.ArtistListView.as_view()),
path('all-artist/<int:pk>', views.ArtistView.as_view())]
0

1 Answer 1

1

You don't need to define the delete() method in the Serializer (and definitely not in the Meta definition).

Delete logic should be handled for you because you derive from RetrieveUpdateDestroyAPIView in your view.

If you want to add custom logic, then you can override perform_destroy() in the view.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.