Django Rest Framework Read Only Model Serializer

You really want to do this at the view (or Viewset) level, which you can do with a ReadOnlyModelViewSet.

(You mentioned this in your comment but I’m leaving it as an answer for better visibility).

For example (from the documentation):

from rest_framework import viewsets


class AccountViewSet(viewsets.ReadOnlyModelViewSet):
    """
    A simple ViewSet for viewing accounts.
    """
    queryset = Account.objects.all()
    serializer_class = AccountSerializer

Leave a Comment