encode / django-rest-framework

Web APIs for Django. 🎸
https://www.django-rest-framework.org
Other
27.83k stars 6.76k forks source link

How to serialize an extended user? #9431

Closed AhmadM-DL closed 3 weeks ago

AhmadM-DL commented 3 weeks ago

I am building an API based application. Users register through an API. For registration an extended user model has been written as proposed by Django documentation:

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete= models.CASCADE)
    phone_number = models.CharField(max_length=25, unique=True, validators=[RegexValidator(r"^\+(?:[0-9] ?){6,14}[0-9]$")])
    language_preferences = models.CharField(max_length= 35)

How to write the signup view and serializer for this model?