我想创建一个用作外键的用户,但我不希望这些用户可以登录系统。我不知道如何继续下去。 (关于设置set_unusable_password()或None,以及如何执行它):
我的accounts.py文件如下
class User(AbstractBaseUser):
GENDER = (("MALE", "Male"), ("FEMALE", "Female"))
user_type = models.CharField(max_length=50, choices=Types.choices, default=Types.PATIENT)
full_name = models.CharField(max_length=255, blank=True, null=True)
phone = models.CharField(max_length=255, unique=True)
email = models.CharField(max_length=255, blank=True, null=True, unique=True)
active = models.BooleanField(default=False)
gender = models.CharField(max_length=15, choices=GENDER)
admin = models.BooleanField(default=False)
staff = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
USERNAME_FIELD = "phone" # username
REQUIRED_FIELDS = []
objects = UserManager()
提前谢谢大家。 <3
最佳答案
您可以使用is_active用户记录字段
is_active Boolean. Designates whether this user account should be considered active. We recommend that you set this flag to False instead of deleting accounts; that way, if your applications have any foreign keys to users, the foreign keys won’t break.
关于python - 创建无法登录的django用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66300963/