简体   繁体   English

Django 具有​​不同超级用户权限和角色的管理站点

[英]Django Admin site with different Superuser permissions and roles

In addition to default superuser " that has access to all apps in the project and all permissions " I want to create two more types of superuser, The maker has able to do All operations Of CRUD on all apps without executing in database in django admin, And the checker has to view one table " operations " to Approve or reject these operations.除了可以访问项目中所有应用程序和所有权限的默认超级用户“我想创建另外两种类型的超级用户,制造商能够在所有应用程序上执行所有 CRUD 操作,而无需在 django 管理员的数据库中执行,并且检查者必须查看一个表“操作”来批准或拒绝这些操作。

  1. is superuser = True是超级用户 = True
  2. is_superuser with is_maker = True is_superuser with is_maker = True
  3. is_superuser with is_checker = True is_superuser with is_checker = True

How could I check the user login in admin.py Django admin site panel to control other stuff?如何在 admin.py Django 管理站点面板中检查用户登录以控制其他内容?

models.py模型.py

class BlogAdmin(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    is_maker = models.BooleanField(blank=True, null=True, default=False)
    is_checker = models.BooleanField(blank=True, null=True, default=False)

class Operation(models.Model):
    name = models.CharField(max_length=255, blank=True, null=True)
    model_name = models.ForeignKey(ContentType, blank=True, null=True,                             on_delete=models.SET_NULL)
    old_value = models.TextField(default='', null=True, blank=True)
    new_value = models.TextField(default='', null=True, blank=True)
    rejection_reason = models.TextField(null=True, blank=True, default='')
    status = models.CharField(choices=STATUS_CHOICES, max_length=50, blank=True, null=True, default=STATUS_PENDING)
    created_by = models.ForeignKey(User, blank=True, null=True, db_column='created_by', on_delete=models.CASCADE)

You must override the default auth-user table that comes with django this way您必须以这种方式覆盖 django 附带的默认 auth-user 表

from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin

class User(AbstractBaseUser, PermissionsMixin):
   name = models.CharField(max_length=50, blank=True, null=True)
   username = models.CharField(max_length=100, unique=True)
   email = models.EmailField(max_length=100, blank=True, null=True)
   gender = models.CharField(max_length=15, blank=True, null=True)
   phone_number = models.CharField(max_length=50, unique=True)
   dob = models.DateField(blank=True,null=True)
   .
   #include everything you needed in user table
   .
   .
   is_maker = models.BooleanField(default=False)
   is_checker = models.BooleanField(default=False)
   .
   is_admin = models.BooleanField(default=False)
   is_staff = models.BooleanField(default=False)
   is_active = models.BooleanField(default=False)
   is_superuser = models.BooleanField(default=False)
   password = models.CharField(('password'), max_length=512 , blank=True, null=True)

You can view more about substituting default user table here substituting custom user model您可以在此处查看有关替换默认用户表的更多信息, 替换自定义用户 model

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 中不同角色的权限 - Permissions to different roles in Django Django admin.site.urls only access to superuser (admin login page only access to superuser) - Django admin.site.urls only accessible to superuser (The admin login page only accessible to superuser) 如何为 django 管理站点创建自定义权限 - How to create custom permissions for django admin site Django 管理站点未显示模型的默认权限 - Django admin site is not showing default permissions of models Django 超级用户没有所有权限 - Django superuser not having all permissions django:管理员通知,如果超级用户显示 - django: admin notifications,display if superuser Django 管理员登录不适用于超级用户 - Django admin login not working for superuser Django 管理应用程序对超级用户 100% 有效,但对于具有完全权限的员工用户,某些应用程序不会为用户显示 - Django admin application works 100% for superuser but for staff users with full permissions some apps don't appear for users 无法验证超级用户或登录Django的管理站点,我做错了什么? - Not able to authenticate superuser or login into admin site in Django, what am I doing wrong? 如何在Django中实现具有不同角色和权限的多种用户类型? - How to implement multiple user types with different roles and permissions in Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM