个人博客系列-后端项目-RBAC角色管理(6)
设计用户表
## 用户表
class User(models.Model):
username = models.CharField(max_length=255, unique=True, verbose_name="手机号")
password = models.CharField(max_length=255, unique=False, verbose_name="密码")
is_vip = models.BooleanField(default=False,verbose_name="是否为vip")
vip_expires_at = models.DateTimeField(auto_now_add=True,verbose_name="vip过期时间")
is_active = models.BooleanField(default=True)
class Meta:
db_table = "user"
verbose_name = "用户表"
verbose_name_plural = verbose_name
创建角色权限表
角色表
# 角色表
class Role(models.Model):
role_name = models.CharField('角色名字', max_length=16)
class Meta:
db_table = "blog_role"
verbose_name = "角色表"
verbose_name_plural = verbose_name
# 权限表
class Access(models.Model):
name = models.CharField('用户权限名称', max_length=256)
path = models.CharField('用户权限路由', max_length=256)
method = models.CharField('用户权限请求方式', max_length=16)
types = models.CharField('权限类型', blank=True, null=True, max_length=10) # 菜单权限和api权限
class Meta:
db_table = "blog_access"
verbose_name = "权限表"
verbose_name_plural = verbose_name
# 用户-角色 多对多
class UserRole(models.Model):
user_id = models.IntegerField('用户ID', null=True, blank=True)
role_id = models.IntegerField('角色ID', null=True, blank=True)
class Meta:
db_table = "blog_user_role"
verbose_name = "用户角色表"
verbose_name_plural = verbose_name
# 角色-权限 多对多
class RoleAccess(models.Model):
role_id = models.IntegerField('角色ID', null=True, blank=True)
acc_id = models.IntegerField('权限ID', null=True, blank=True)
class Meta:
db_table = "blog_role_access"
verbose_name = "角色权限表"
verbose_name_plural = verbose_name
数据库迁移
python manage.py makemigrations
python manage.py migrate
原文地址:https://blog.csdn.net/weixin_45983953/article/details/136511962
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!