Reputation: 8187
This is my code
from rest_framework import serializers
from django.contrib.auth import get_user_model
User = get_user_model()
class UserSerializer(serializers.ModelSerializer):
username = serializers.Field(source="username", required = False)
class Meta:
model = User
fields = ('first_name', 'last_name', 'username')
It seems so straight forward. What is the issue?
Upvotes: 1
Views: 3472
Reputation: 3865
Change it to CharField
and add allow_blank=True
username = serializers.CharField(source="username",
required = False,
allow_blank=True)
Upvotes: 0
Reputation: 22697
Change it to CharField
.
username = serializers.CharField(source="username", required = False)
Upvotes: 1