Перенесите часть кода из метода GenericAPIView post в другие методы в django
У меня есть мой django GenericAPIView с методом post, я хочу, чтобы часть логики, которая использует self, находилась в каком-то другом методе и выполняла этот код, когда мой метод post получает вызов
class MyAPIView(models.Model):
def post(self, request, *args, **kwargs):
Вы можете сделать что-то вроде этого!
class MyAPIView(CreateAPIView):
def custom_function(self):
"""place your logic here!"""
pass
def post(self, request, *args, **kwargs):
# This will call our custom function as soon as post request is hit
self.custom_function()
return super().post(request, *kwargs, *args)