| | 1044 | |
| | 1045 | Optionally the Backend allows you to specify any of the permission methods of |
| | 1046 | the ``User`` object (except from ``has_perms`` which calls ``has_perm`` for each |
| | 1047 | perm in the list, and ``has_perm`` can be specified in the backend). |
| | 1048 | This will allow your backend to handle the permissions, if one backend return |
| | 1049 | ``True`` in a permission check, the user will have the permission. |
| | 1050 | |
| | 1051 | Here is an sample implementation for ``has_perm`` extending the above exmaple:: |
| | 1052 | |
| | 1053 | # The permission functions all take the user_obj as first (besides the self of |
| | 1054 | # the backend, of course) argument and the rest |
| | 1055 | # is as you would call it with ``User.*`` |
| | 1056 | def has_perm(self, user_obj, perm): |
| | 1057 | # we give the user admin the right to do everything. |
| | 1058 | if user_obj.username == "admin": |
| | 1059 | return True |
| | 1060 | else: |
| | 1061 | return False |
| | 1062 | |
| | 1063 | A full implementation can be found in ``django/contrib/auth/backends.py`` _, which is the |
| | 1064 | default backend and queries the ``auth_permission``-table most of the time. |
| | 1065 | |
| | 1066 | .. _django/contrib/auth/backends.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/backends.py |