From 5f32c0ebd254a4b4fc85392cbc962873f2b6df85 Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Wed, 28 Aug 2019 17:02:30 -0300 Subject: [PATCH] add __str__ nos resultados da api --- sapl/api/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sapl/api/views.py b/sapl/api/views.py index 6f4e9219a..9ddafb9ec 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -15,6 +15,7 @@ from django_filters.rest_framework.filterset import FilterSet from django_filters.utils import resolve_field from rest_framework import serializers as rest_serializers from rest_framework.decorators import action +from rest_framework.fields import SerializerMethodField from rest_framework.response import Response from rest_framework.viewsets import ModelViewSet @@ -94,10 +95,15 @@ class SaplApiViewSetConstrutor(): # Define uma classe padrão para serializer caso não tenha sido # criada a classe sapl.api.serializers.{model}Serializer class SaplSerializer(rest_serializers.ModelSerializer): + __str__ = SerializerMethodField() + class Meta: model = _model fields = '__all__' + def get___str__(self, obj): + return str(obj) + # Define uma classe padrão para filtro caso não tenha sido # criada a classe sapl.api.forms.{model}FilterSet class SaplFilterSet(SaplFilterSetMixin):