I've read tons of stack overflow posts about how to register a user with email instead of username but none of them seem to work, so I'm resetting to my defaults. I tried this and this but I still get 'username is required' back from the API when I try to register user.
I think the problem might be that I couldn't find a post that's explicit to Django 3 and uses Django Rest Framework.
Below are my models, serializers and views.
# models
class User(AbstractUser):
ROLES = (
('d', 'Doctor'),
('s', 'Secretary'),
('p', 'Patient'),
)
role = models.CharField(
max_length=1, choices=ROLES, blank=True, default='p', help_text='Role')
class Doctor(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
clinic = models.ManyToManyField(
Clinic, related_name="doctors", blank=True)
appointment_duration = models.IntegerField(default=20, blank=True)
# serializer
User = get_user_model()
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'password', 'role', 'first_name', 'last_name', 'email', 'phone')
extra_kwargs = {'password': {'write_only': True, 'required': True}
# viewset
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (AllowAny,)
So, how could I register with email instead of username?