[英]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 管理员的数据库中执行,并且检查者必须查看一个表“操作”来批准或拒绝这些操作。
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.