I'm using SlugRelatedField in my serializer. I want to validate it on a case-insensitive basis, so I add postfix "__iexact" to the "slug_field" attr. And validation works as I need (case-insensitive).
class MySerializer(ModelSerializer):
customer = serializers.SlugRelatedField(queryset=Customer.objects.all(),
required=False,
allow_null=True,
slug_field='name__iexact')
But when I try to get serializer.data, the following error occurs:
* {AttributeError}'Customer' object has no attribute 'name__iexact'
How can it be solved?
AFAIK, there is no official implementation to make that happen - but, you can create a custom field out of
SlugRelatedField(...)something like below,and use it as