Wish to have more detail in serializer, looking for tags should be nested with all the items
MicroDreamIT opened this issue · 2 comments
MicroDreamIT commented
here is my Model is look like
model.py
class Event(models.Model):
title = models.CharField(max_length=151, db_index=True)
description = models.TextField(blank=True, null=True)
tags = TaggableManager()
serializers.py
class EventSerializer(serializers.ModelSerializer):
slug = serializers.SerializerMethodField()
tags = TagListSerializerField()
the Result I am having:
{
"id": 52,
"slug": "52-aperiam-amet",
"tags": [
"hello",
"world"
],
"title": "Aperiam amet",
"description": "Quibusdam ipsum sun Quibusdam ipsum sun Quibusdam ipsum sun ",
},
but expected tags nest should look like
"tags": [
{
id:"1",
slug:'1-hello',
name:"hello"
},
{
id:"2",
slug:'2-world',
name:"world"
},
],
rtpg commented
I'm not going to outright close this because it might make sense to have some extra serializers, but we can't change the existing one.
I think it makes sense to have both, because in many use cases you don't want to expose the tag ID.
Let's keep this open and maybe we can have someone contribute a more detailed serializer for those who want it 👍 At the very least we can write a very small doc guide to just point out how to easily do this with DRF