<filename>myblog/posts/serializer.py
from django.contrib.auth.models import User
from rest_framework import serializers
from .models import Post


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'username', 'email')


class PostSerializer(serializers.ModelSerializer):
    author = serializers.ReadOnlyField(source='author.username')
    # author = UserSerializer(read_only=True)

    class Meta:
        model = Post
        fields = '__all__'

<filename>myblog/posts/serializer.py
from django.contrib.auth.models import User
from rest_framework import serializers
from .models import Post


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'username', 'email')


class PostSerializer(serializers.ModelSerializer):
    author = serializers.ReadOnlyField(source='author.username')
    # author = UserSerializer(read_only=True)

    class Meta:
        model = Post
        fields = '__all__'

# author = UserSerializer(read_only=True)