В общем расклад такой.
В модели добавляем метод
get_scope()
class CustomUser(AbstractBaseUser, PermissionsMixin):
USER_TYPE_CHOICES = (
(1, 'customer'),
(2, 'manufacturer'),
(3, 'seller'),
)
name = models.CharField(max_length=50, null=True, blank=True)
phone = models.CharField(max_length=12, verbose_name='Телефон')
email = models.EmailField('Адрес электронной почты', unique=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)
user_type = models.PositiveSmallIntegerField(choices=USER_TYPE_CHOICES)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
def get_scope(self):
arr = []
arr.append(self.get_user_type_display())
return arr
def __str__(self):
return self.email
Ну и правим сам serializer
class UserSerializer(serializers.ModelSerializer):
user_type = serializers.ListField(source='get_scope')
# scope = serializers.CharField(source='get_user_type_display')
def create(self, validated_data):
return get_user_model().objects.create_user(**validated_data)
class Meta:
model = get_user_model()
fields = ('email', 'password', 'phone', 'name', 'user_type')
extra_kwargs = {
'password': {'write_only': True, 'min_length': 8},
}