Пытаюсь вывести дополнительное поле с помощью SerializerMethodField но на выходе не получаю результата.
class SampleSerializer(serializers.HyperlinkedModelSerializer):
...
...
new = serializers.SerializerMethodField()
class Meta:
model = Platform
def get_new(self, obj):
value = getattr(obj, 'new', False)
return value
views.py
class MyAuthView(APIView):
permission_classes = (permissions.IsAuthenticated,)
def post(self, request, *args, **kwargs):
.....
some code
.....
try:
...some code...
try:
p = Platform.objects.get(
content_type=ContentType.objects.get_for_model(y),
object_id=y.id,
user=request.user
)
except:
p = Platform(user=request.user,
platform=y, description=description)
new = False <------- новая переменная
except Youtube.DoesNotExist:
p = Platform(user=request.user,
platform=y, description=description)
new = True <------- новая переменная
return Response(
PlatformSerializer(p, context={'request': request}).data
)
Подскажите чего не хватает?