[Answered ]-Django-taggit: can not have all the data with key in tags object

1👍

You can work with a TagSerializer:

from taggit.models import Tag


class TagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tag
        fields = ('id', 'name', 'slug')

and then work with:

class EventSerializer(serializers.ModelSerializer):
    slug = serializers.SerializerMethodField()
    tags = TagSerializer(many=True)

That being said, essentially Taggit aims to hide the tag model and expose it as just strings, this is likely the main task django-taggit aims to achieve, and likely is better since exposing the primary key makes it more complicated.

Leave a comment