old_contents: from django.contrib.auth.models import User
  from rest_framework import permissions
  from rest_framework import serializers, viewsets
  from rest_framework.pagination import PageNumberPagination
  from rest_framework.permissions import BasePermission
  
  from blog.models import Blog
  
  SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
  
  
  class IsAuthenticatedOrReadOnly(BasePermission):
      def has_permission(self, request, view):
          if (request.method in SAFE_METHODS or
                      request.user and
                      request.user.is_authenticated()):
              return True
          return False
  
  
  class BlogSerializer(serializers.ModelSerializer):
      author = User
  
      class Meta:
          model = Blog
          fields = ('title', 'author', 'body', 'slug', 'id')
  
  
  class BlogSet(viewsets.ModelViewSet):
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
      serializer_class = BlogSerializer
      queryset = Blog.objects.all()
  
new_contents: from django.contrib.auth.models import User
  from rest_framework import permissions
  from rest_framework import serializers, viewsets
  
  from blog.models import Blog
  
  SAFE_METHODS = ['GET', 'HEAD', 'OPTIONS']
  
  
  class BlogSerializer(serializers.ModelSerializer):
      author = User
  
      class Meta:
          model = Blog
          fields = ('title', 'author', 'body', 'slug', 'id')
  
  
  class BlogSet(viewsets.ModelViewSet):
      permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
      serializer_class = BlogSerializer
      queryset = Blog.objects.all()
  
subject: simplify code