[Answered ]-Get Reverse relations object in rest framework

2👍

✅

The related_name will only return id’s, and this is not wrong at all. If you want the full representation, you will also need to add a serialized version of each child object in your parent. Like this:

class PostSerializer(serializers.ModelSerializer): 
    category = CategorySerializer(many=True, required=False)

So you first need to have a CategorySerializer, and then you must add the relationship in the PostSerializer. All parameters are optional. Here is a small example.

P.S. : I suggest using ‘categories’ as related_name, since you can have more than just one.

Leave a comment