Skip to content

Commit

Permalink
make arctic role models swappable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron van der Vegt committed Oct 10, 2016
1 parent a34389e commit 4b585a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 8 additions & 2 deletions arctic/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-07-30 20:16
# Generated by Django 1.9.6 on 2016-10-10 13:54
from __future__ import unicode_literals

from django.conf import settings
Expand All @@ -23,13 +23,19 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=100, unique=True, verbose_name='Role')),
('is_active', models.BooleanField(default=True)),
],
options={
'swappable': 'ARCTIC_ROLE_MODEL',
},
),
migrations.CreateModel(
name='UserRole',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='arctic.Role')),
('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=getattr(settings, 'ARCTIC_ROLE_MODEL', 'arctic.Role'))),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='urole', to=settings.AUTH_USER_MODEL)),
],
options={
'swappable': 'ARCTIC_USER_ROLE_MODEL',
},
),
]
8 changes: 7 additions & 1 deletion arctic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

class UserRole(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='urole')
role = models.ForeignKey('Role')
role = models.ForeignKey(settings.ARCTIC_ROLE_MODEL)

class Meta:
swappable = 'ARCTIC_USER_ROLE_MODEL'


class Role(models.Model):
Expand All @@ -13,3 +16,6 @@ class Role(models.Model):

def __str__(self):
return self.name

class Meta:
swappable = 'ARCTIC_ROLE_MODEL'
3 changes: 3 additions & 0 deletions example/example/arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
)),
)

ARCTIC_USER_ROLE_MODEL = 'arctic.UserRole'
ARCTIC_ROLE_MODEL = 'arctic.Role'

ARCTIC_ROLES = {
'editor': (
'articles_view',
Expand Down

0 comments on commit 4b585a6

Please sign in to comment.