Skip to main content

Add roles to django-auth

Project description

Code Climate https://travis-ci.org/tomi77/django-auth-role.svg?branch=master https://coveralls.io/repos/github/tomi77/django-auth-role/badge.svg?branch=master

Add roles to django-auth

Installation

pip install django-auth-role

Quick start

Add authrole to INSTALLED_APPS. django.contrib.auth and django.contrib.contenttypes are also required.

INSTALLED_APPS = [
    ...
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'authrole',
]

Extend auth.User.

from django.db import models

class MyUser(models.Model):
    role = models.ForeignKey('authrole.Role', related_name='myusers')
    user = models.OneToOneField('auth.User', related_name='user')

Create tables.

./manage.py migrate

Extend Your own authentication backend.

from authrole.auth.backends import BaseAuthRoleBackend

class MyBackend(BaseAuthRoleBackend):
    def fetch_role_permissions(self, user_obj):
        return Permission.objects.filter(group__roles__myusers__user=user_obj)

And add it to AUTHENTICATION_BACKENDS.

AUTHENTICATION_BACKENDS = (
    'app.MyBackend',
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

django_auth_role-0.1.0-py2.py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page