This is my serializer:
class MetaDataSerializer(serializers.Serializer):
bg_colors = ColorSerializer(Color.objects.all(), many=True)
button_choices = serializers.SerializerMethodField()
class Meta:
fields = ('bg_colors', 'button_choices')
def get_button_choices(self, obj):
return {
'save': 1, 'continue': 2, 'cancel': 3, 'back': 4
}
I'm calling this serializer from my view like this:
class MetaDataView(RetrieveAPIView):
serializer_class = MetaDataSerializer
def get(self, request, *args, **kwargs):
return Response(self.get_serializer().data)
In the response I'm getting only the bg_colors field. The other field is absent from response, and its get_field method is also not called.
What am I doing wrong here?