Skip to content

Instantly share code, notes, and snippets.

@paulonteri
Created August 24, 2020 13:13
Show Gist options
  • Save paulonteri/7d231f7e4755f35f3f18c850967a1800 to your computer and use it in GitHub Desktop.
Save paulonteri/7d231f7e4755f35f3f18c850967a1800 to your computer and use it in GitHub Desktop.
Override list method in DRF ModelViewSet
# Students View
class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
serializer_class = StudentSerializer
permission_classes = perms
def list(self, request, *args, **kwargs):
queryset = Student.objects.all().only("student_id", "first_name", "surname", "gender", "class_ns", "dormitory")
serializer = StudentLessDataSerializer(queryset, many=True)
return Response(serializer.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment