在不干扰django管理站点的情况下验证最终用户

oyxsuwqo  于 2023-05-08  发布在  Go
关注(0)|答案(1)|浏览(129)

首先,我登录到django管理站点,然后我转到我的html模板中的登录页面并注销,但当我再次转到django管理站点时,django管理站点也注销了。我该如何区分这两件事,以便当终端用户登录和注销时不会影响django管理员?
我的项目使用自定义用户模型,这是所有没有别的。

class MyAccountManager(BaseUserManager):
    def create_user(self, username, first_name, middle_name, last_name, club_favorite, email, password=None):
        if not username:
            raise ValueError("Users must have a username")
        user = self.model(
            username = username,
            first_name = first_name,
            middle_name = middle_name,
            last_name = last_name,
            club_favorite = club_favorite,
            email = email,
        )
        
        user.set_password(password)
        user.save(using=self._db)
        return user
    
    def create_superuser(self, username, first_name, middle_name, last_name, club_favorite, email, password=None):
        user = self.create_user(
            username,
            password = password,
            first_name = first_name,
            middle_name = middle_name,
            last_name = last_name,
            club_favorite = club_favorite,
            email = email,
        )
        user.is_admin = True
        user.save(using=self._db)
        return user

class MyAccount(AbstractBaseUser):
    first_name = models.CharField(max_length=100)
    middle_name = models.CharField(max_length=100, blank=True)
    last_name = models.CharField(max_length=100, blank=True)
    username = models.CharField(max_length=100, unique=True)
    email = models.EmailField(max_length=254, blank=True)
    club_favorite = models.CharField(max_length=100)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    
    object = MyAccountManager()
    
    USERNAME_FIELD =    'username'
    REQUIRED_FIELDS = ['first_name', 'middle_name', 'last_name', 'club_favorite', 'email']
    
    def __str__(self):
        return self.username
    
    def has_perm(self, perm, obj=None):
        return True
    
    def has_module_perms(self, app_label):
        return True
    
    @property
    def is_staff(self):
        "Is the user a member of staff?"
        # Simplest possible answer: All admins are staff
        return self.is_admin

需要解决方案........................................

oaxa6hgo

oaxa6hgo1#

a)用户和管理员会话可以使用不同的浏览器
B)您可以在隐私模式下使用浏览器

相关问题