I'm trying to implement a user registration and authentication using django rest framework and I'm not sure how to implement it.
The thing is that I want a user to have multiple usernames/nicknames so that's why I have a little bit troubles.
The current models I have:
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=50,
unique=True,
error_messages={
'unique': _("Email already exists."),
},
)
is_active = models.BooleanField(
_('active'),
default=True,
help_text=_(
'Designates whether this user should be treated as active. '
'Unselect this instead of deleting accounts.'
),
)
gender = models.IntegerField(default=GENDER_MALE, choices=GENDER_CHOICES)
date_of_birth = UnixDateTimeField(null=True, blank=True, )
ip = models.GenericIPAddressField(null=True)
USERNAME_FIELD = 'email'
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
class UserNicknames(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
username = models.CharField(max_length=10,
null=False,
unique=True,
validators=[username_validator],
error_messages={
'unique': _("A user with that username already exists."),
},
)
is_current = models.BooleanField(default=False)
As you can see I have the User model just like the django one but without the username and UserNicknames which contains the user nicknames (the UserNicknames.user field is the foreign key to the User.id field).
The question is what is right way to implement the registration serializer? Should I get all the fields in User and UserNicknames and then do the logic or there is some smarter way to do it?
