标签:spl bubuko red mode man cfile pps port str
拷贝之前写好的rbac应用到CRM_demo项目下。
在settings中注册rbac的app:
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘crm.apps.CrmConfig‘, ‘stark.apps.StarkConfig‘, ‘rbac.apps.RbacConfig‘ ]
settings中添加rabc中间件:
from rbac.models import * class UserInfo(models.Model): """ 员工表 """ name = models.CharField(verbose_name=‘员工姓名‘, max_length=16) username = models.CharField(verbose_name=‘用户名‘, max_length=32) password = models.CharField(verbose_name=‘密码‘, max_length=64) email = models.EmailField(verbose_name=‘邮箱‘, max_length=64) # 模仿 SQL 约束 ON DELETE CASCADE 的行为,换句话说,删除一个对象时也会删除与它相关联的外键对象。 depart = models.ForeignKey(verbose_name=‘部门‘, to="Department", to_field="code", on_delete=models.CASCADE) user = models.OneToOneField(to=User, null=True, on_delete=models.CASCADE) def __str__(self): return self.name
由于是临时添加的字段,因此添加参数null=True。
然后完成数据迁移:
manage.py@CRM_demo > makemigrations manage.py@CRM_demo > migrate
from stark.service.stark import site,ModelStark from .models import * class UserConfig(ModelStark): list_display = ["name", "roles"] site.register(User, UserConfig) class RoleConfig(ModelStark): list_display = ["title", "permissions"] site.register(Role, RoleConfig) class PermissionConfig(ModelStark): list_display = ["id", "title", "url", "group", "action"] site.register(Permission, PermissionConfig) site.register(PermissionGroup)
注意:
原来在models.py中配置url的max_length=32这个长度不够输入全部路径,因此将其改为max_length=64。
编辑操作的url取的是crm应用的路径在这里是change,但action取的是rbac的操作分类是edit。
{% extends ‘base.html‘ %} {% block con %} <h4>角色列表</h4> {% if per.add %} <a href="/roles/add" class="btn btn-primary">添加角色</a> {% endif %} <table class="table table-bordered table-striped"> <tbody> {% for role in role_list %} <tr> <td>{{ forloop.counter }}</td> <td>{{ role.title }}</td> <td> {% if per.delete %} <a href="/roles/delete/{{ user.pk }}" class="btn btn-danger">删除</a> {% endif %} {% if per.edit %} <a href="/roles/edit/{{ user.pk }}" class="btn btn-warning">编辑</a> {% endif %} </td> </tr> {% endfor %} </tbody> </table> {% endblock %}
这个是点击学生表对应查看的,不能放在菜单栏中,因此不能将action设为list.
给每个员工分配对应的user:
标签:spl bubuko red mode man cfile pps port str
原文地址:https://www.cnblogs.com/xiugeng/p/9565581.html