Answer the question
In order to leave comments, you need to log in
How to make registration of new Django users by invites (invitations) from other users?
It is required to register a user using an invite code received from a previously registered user
. The user enters an invite and a password. The system generates a nickname itself in case of a successfully found invite.
At the time of registration, the system checks the invite, in case of successful finding it generates a username, by invite it finds the nickname of the one who invited the registered user and creates a record about the new user (see code)
The model is as follows:
# myapp/model.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
class Users(AbstractBaseUser):
def login_gen():
import uuid
uuid = uuid.uuid4()
return str(uuid)[:8], uuid
id = models.BigAutoField(primary_key=True)
username = models.CharField("Имя пользователя", max_length=8, null=False, blank=False, db_index=True, unique=True, default=login_gen()[0])
password = models.CharField("Пароль", max_length=255, null=False, blank=False)
role = models.BooleanField("Физ или юр", null=False, blank=False)
inviter = models.ForeignKey(verbose_name='Кто пригласил', self.id, null=False, blank=False)
#... другие поля
UUID = models.UUIDField("UUID", null=False, blank=False, default=login_gen()[1])
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['username', 'password', 'role']
def __str__(self):
return self.username
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question