Django 권한

21578 단어 Django
from django.db import models


class Permission(models.Model):
	#     
	name = models.CharField(_('name'), max_length=255)
    #   (         )
    codename = models.CharField(_('codename'), max_length=100)
    #         (  )
    content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
	
    class Meta:
        proxy = True
        default_permissions = ()
        verbose_name = 'permission'
        verbose_name_plural = 'permissions'
        permissions = (
            ('list_permission', _('Can see permission list')),
            ('assign_resource', _('Can assign resource to user')),
        )	

class ContentType(models.Model):
	#    
    app_label = models.CharField(max_length=100)
    #    
    model = models.CharField(_('python model class name'), max_length=100)


class Group(models.Model):
	#   
	name = models.CharField(_('name'), max_length=80, unique=True)
	description = models.CharField(_('description'), max_length=255, blank=True)
	parent_id = models.IntegerField(_('parent ID'))
	#     (   :           ,            )
    permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True)

    class Meta:
        proxy = True
        verbose_name = 'role'
        verbose_name_plural = 'roles'
        default_permissions = ()
        permissions = (
            ('list_role', _('Can see role list')),
            ('detail_role', _('Can see role detail')),
            ('create_role', _('Can create role')),
            ('update_role', _('Can update role')),
            ('delete_role', _('Can delete role')),
            ('update_role_permission', _('Can update role permission')),
            ('update_role_user', _('Can update role user')),
        )

class User(models.Model):
	password = models.CharField(_('password'), max_length=128)
    last_login = models.DateTimeField(_('last login'), blank=True, null=True)
    is_active = True
    REQUIRED_FIELDS = []

	is_superuser = models.BooleanField()
	
	#      (   :           ,           )
	groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True, related_name="user_set", related_query_name="user")
	#       (   :          ,              )
    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, related_name="user_set", related_query_name="user")
    
    username = models.CharField( _('username'), max_length=150, unique=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=150, blank=True)
    email = models.EmailField(_('email address'), blank=True)
    is_staff = models.BooleanField(_('staff status'), default=False)
    is_active = models.BooleanField(_('active'), default=True)
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

    class Meta:
        db_table = 'auth_user'
        verbose_name = 'user'
        verbose_name_plural = 'users'
        # ordering = ['-id']
        permissions = (
            ('list_user', _('Can see user list')),
            ('detail_user', _('Can see user detail')),
            ('create_user', _('Can create user')),
            ('update_user', _('Can update user')),
            ('delete_user', _('Can delete user')),
            ('update_user_permission', _('Can update user permission')),
            ('update_user_role', _('Can update user role')),
            # ('update_user_team', _('Can update user team')),
            ('reset_password', _('Can reset user password')),
            ('active_user', _('Can active or inactive user')),
        )
        default_permissions = ()

좋은 웹페이지 즐겨찾기