customise the django rest api view 1

customise the django rest api view

def update(self, request, *args, **kwargs):
    data = request.DATA
    qs = Student_academic_program.objects.filter(student=2773951)
    serializer = StudentAcademicProgramSerializer(qs, data=data, many=True)

    if serializer.is_valid():
        serializer.save()

        return Response(serializer.data)

    ...

Here is what the above code is Doing:
1. Get the data from the request
2. Get the queryset of objects to update
3. Create a serializer with the queryset and the data
4. Check if the serializer is valid
5. If it is, save the serializer and return the data
6. If it isn’t, return the errors

Similar Posts