'After overriding create function, how to the get the id of the newly created object in django?
I have a ModelViewSet and I want to perform some more operations on the newly created object. But I am unable to get the newly created object id here. How to get the newly created object id after the super()?
def create(self, request, *args, **kwargs):
phone = request.data.get('student_phone_number')
batch_id = request.data.get('batch_id')
class_number = request.data.get('class_number')
if not any([phone, batch_id, class_number]):
return Response({"message": "Missing Params"}, status=status.HTTP_400_BAD_REQUEST)
if self.queryset.filter(student_phone_number=phone, batch_id=batch_id, class_number=class_number,
is_cancelled=False).exists():
return Response({"message": "Compensation class already booked"}, status=status.HTTP_400_BAD_REQUEST)
super().create(request, *args, **kwargs)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
