Created
August 24, 2020 13:13
-
-
Save paulonteri/7d231f7e4755f35f3f18c850967a1800 to your computer and use it in GitHub Desktop.
Override list method in DRF ModelViewSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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