I am quite new DRF so I am sorry beforehand for any mistake.
For example, I have Post model which has Author as foreign key to NewUser model. When I list posts, instead of getting primary key of author, I wanted to get nested object with author details and that is why I created my serializer like this.
class PostAuthorSerializer(serializers.ModelSerializer):
class Meta:
model = NewUser
fields = ["id", "email", "user_name"]
class PostSerializer(serializers.ModelSerializer):
author = PostAuthorSerializer()
class Meta:
model = Post
read_only_fields = ("slug",)
fields = (
"id",
"title",
"author",
"excerpt",
"content",
"status",
"slug",
)
lookup_field = "slug"
However, now I don`t how to /POST a post back. I searched for 2 days but cannot find a proper guide for understand how to do. My main goal is to learn/understand rather than solve the issue so a little bit explanation also would be great! I was really motivated to learn DRF, but I think it lacks a detailed documentation and examples in internet or at least I could not find answer to my question.
So, I want to learn 2 ways of posting:
- Representation is staying this way but I still /POST a post with showing "author":id
- Representation is staying this way and I /POST "author: {"email": "[email protected]", "user_name":"orkan.test"}" and still can create my post after getting author object
Thanks in advance!

