Hello I have a serialiser and I'd like to have one field type for the GET requests and anther field for the POST requests.
These are my serialisers:
class TypeSerializer(serializers.Serializer):
id = serializers.CharField()
name = serializers.CharField(max_length=50)
colour = serializers.CharField(max_length=8)
class UserSerializer(serializers.Serializer):
id = UUIDField(format="hex_verbose")
name = serializers.CharField()
type = TypeSerializer()
So the response is something like this:
{
"id": "987328lf-93ad-21ba-2648-h2u7b95d5cf",
"name": "name",
"type": {
"id": "RANDOM_ID",
"name": "Type 1",
"colour": "#ffffff"
}
}
That's what I want on the GET, but on the POST I'd like to send a payload like this:
{
"name": "New name",
"type": "RANDOM_ID"
}
I will get a 500 error because type is expected to be a dictionary.
Anyone knows if its posible to have one field for GET and another field for POST without creating another serialiser?