In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to create a RBAC rights management model in myblog-django? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Write the following model under user/model.py
From django.dbimport modelsfrom django.contrib.auth.modelsimport AbstractUser# Create your models here.class Menu (models.Model): name= models.CharField (max_length=25,unique=True,verbose_name=' menu name') url = models.CharField (max_length=125,unique=True,null=True,blank=True,verbose_name='URL') parent = models.ForeignKey ("self", null=True,blank=True,on_delete=models.SET_NULL,verbose_name=' parent menu') code = models.CharField (max_length=50,null=True,blank=True Verbose_name=' Encoding') icon = models.CharField (max_length=50,null=True,blank=True,verbose_name=' icon') def _ _ str__ (self): return self.nameclass Meta:verbose_name=' menu 'verbose_name_plural=verbose_namedb_table='tb_menu'class Role (models.Model): "" role binding "" name= models.CharField (max_length=35,unique=True,verbose_name=' role name') permissions = models.ManyToManyField (Menu,blank=True) Verbose_name='URL Authorization') desc = models.CharField (max_length=50,blank=True,null=True,verbose_name= "description") def _ _ str__ (self): return self.nameclass Meta:verbose_name=' role 'verbose_name_plural=verbose_namedb_table='tb_role'class UserProfile (AbstractUser): name= models.CharField (max_length=20,default= ", verbose_name=" name ") birthday = models.DateField (null=True,blank=True,verbose_name=" date of birth ") gender = models.CharField (max_length=10 Choices= (("male", "male"), ("female", "female")), default= "nale", verbose_name= "gender") image = models.ImageField (upload_to= "image/avatar/%Y/%m", default= "iamge/avatar/default.jpg", max_length=100,null=True,blank=True) roles = models.ManyToManyField (Role,verbose_name= "role") Blank=True) def _ _ str__ (self): return self.nameclass Meta:verbose_name= "user Information" verbose_name_plural=verbose_namedb_table= "tb_userprofile" ordering= ['id']
Then make the migration script
Python manage.py makemigrations
Execute the migration script
Python manage.py migrate
At this time, the data table of the database is also created successfully
This is the answer to the question about how to create a RBAC rights management model in myblog-django. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.