django中自定议rbac权限model类

from django.db import models

# Create your models here.

class Permission(models.Model):
    ‘‘‘
    权限表
    ‘‘‘
    title = models.CharField(verbose_name=‘标题‘, max_length=32)
    url = models.CharField(verbose_name=‘含正则的URL‘, max_length=128)
    is_menu = models.BooleanField(verbose_name=‘是否可做菜单‘, default=False)
    icon = models.CharField(verbose_name=‘图标‘, max_length=32, null=True, blank=True)

    def __str__(self):
        return self.title

class Role(models.Model):
    ‘‘‘
    角色表
    ‘‘‘
    title = models.CharField(verbose_name=‘角色‘, max_length=32)
    permission = models.ManyToManyField(verbose_name=‘拥有的所有权限‘, to=‘Permission‘, blank=True)

    def __str__(self):
        return self.title

class UserInfo(models.Model):
    ‘‘‘
    用户表
    ‘‘‘
    name = models.CharField(verbose_name=‘用户名‘, max_length=32)
    password = models.CharField(verbose_name=‘密码‘, max_length=64)
    email = models.CharField(verbose_name=‘邮箱‘, max_length=32)
    role = models.ManyToManyField(verbose_name=‘担任的角色‘, to=‘Role‘, blank=True)

    def __str__(self):
        return self.name

相关推荐