[Answered ]-How to access model's verbose name in a serializer?

1👍

You can do something like the following:

class ProductCategorySerializer(serializers.ModelSerializer):
    device_types = serializers.StringRelatedField(many=True)
    device_brands = serializers.StringRelatedField(many=True)
    part_types = serializers.StringRelatedField(many=True)
    plural_name = serializers.SerializerMethodField()

    def get_plural_name(self, obj):
        return ProductCategory._meta.verbose_name_plural

    class Meta:
        model = ProductCategory
        fields = ('name', 'device_types', 'device_brands', 'part_types', 'plural_name')

Leave a comment