row level permissions in django

后端 未结 5 1895
一个人的身影
一个人的身影 2021-01-30 15:19

Is there a way to do row level permissions in django? I thought there wasn\'t but just noticed this in the docs:

Permissions can be set not only per type

5条回答
  •  终归单人心
    2021-01-30 15:38

    The plumbing is there (this is from the bottom of the same page you linked):

    Handling object permissions

    Django's permission framework has a foundation for object permissions, though there is no implementation for it in the core. That means that checking for object permissions will always return False or an empty list (depending on the check performed). An authentication backend will receive the keyword parameters obj and user_obj for each object related authorization method and can return the object level permission as appropriate.

    But no default implementation is provided. Since this is a common topic; there are lots of answers on SO. Check to the right and you'll see some listed.

    The basis idea is to browse the django packages' perm grid and pick an implementation of object level permissions. I personally like django-guardian.

提交回复
热议问题