码迷,mamicode.com
首页 > 其他好文 > 详细

Django之自定义权限

时间:2017-04-07 18:03:29      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:...   extra   sig   actions   charge   http   ica   nec   custom   

官方解释

Custom permissions?

To create custom permissions for a given model object, use the permissions model Meta attribute.

This example Task model creates three custom permissions, i.e., actions users can or cannot do with Task instances, specific to your application:

class Task(models.Model):
    ...
    class Meta:
        permissions = (
            ("view_task", "Can see available tasks"),
            ("change_task_status", "Can change the status of tasks"),
            ("close_task", "Can remove a task by setting its status as closed"),
        )

The only thing this does is create those extra permissions when you run manage.py migrate (the function that creates permissions is connected to the post_migrate signal). Your code is in charge of checking the value of these permissions when a user is trying to access the functionality provided by the application (viewing tasks, changing the status of tasks, closing tasks.) Continuing the above example, the following checks if a user may view tasks:

user.has_perm(‘app.view_task‘)

 

项目实战

 

Django之自定义权限

标签:...   extra   sig   actions   charge   http   ica   nec   custom   

原文地址:http://www.cnblogs.com/kongzhagen/p/6679365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!