image.png
一、思路
+##### 权限下对应多个地址,所以用户和权限下的连接就会出现重复对应
-
用户和权限应该是多对多,也就是一个用户可以有多个权限,一个权限对应多个用户,普通人员有普通的权限,老板既可以有普通权限也可以有自己的权限
-
网站权限拆分,一般一个网站有多个网址,他们分别对应增删改操作,为了让权限更加细致化,我们把增删改查,从网址中拆出来
-
拆分出来的网址和权限形成多对多关系
class userinfo(models.Model):
nid = models.AutoField(primary_key=True)
username = models.CharField(max_length=32,unique=True)
password = models.CharField(max_length=64)
nickname = models.CharField(max_length=32)
email = models.EmailField(unique=True)
creat_time = models.DateTimeField(auto_now_add=True)
admin_choice = [
(1,'普通用户'),
(2,'工程师'),
(3,'boss'),
]
admin = models.IntegerField(choices=admin_choice,default=1)
class Role(models.Model):
'''
权限
'''
caption = models.CharField(max_length=32)
class Meta:
verbose_name_plural = "权限"
def __str__(self):
return self.caption
class User2Role(models.Model):
'''
用户和权限的关系
'''
u = models.ForeignKey('userinfo')
r = models.ForeignKey(Role)
class Meta:
verbose_name_plural = "用户权限"
def __str__(self):
return '%s-%s'%(self.u.username,self.r.caption)
class Acion(models.Model):
#get 获取用户
#post 获取用户
#delete 获取用户
#put 获取用户
code = models.CharField(max_length=32)
capation = models.CharField(max_length=32)
class Menu(models.Model):
'''
创建关联菜单,创建菜单
'''
caption = models.CharField(max_length=32)
parent = models.ForeignKey('self',related_name='p',null=True,blank=True)
class Url(models.Model):
'''
连接
'''
#http://127.0.0.1:8000/user.htnl
caption = models.CharField(max_length=32)
url = models.CharField(max_length=32)
#和 菜单关联
menu= models.ForeignKey(Menu,null=True,blank=True)
class Meta:
verbose_name_plural = "url"
def __str__(self):
return self.caption
class Url2Action(models.Model):
'''
组合连接
'''
url = models.ForeignKey(Url)
a = models.ForeignKey(Acion)
class Url2Action2Role(models.Model):
'''
连接分支和权限的关系
'''
url2a = models.ForeignKey(Url2Action)
r = models.ForeignKey(Role)
网友评论