jumpserver/juser/models.py

55 lines
1.5 KiB
Python
Raw Normal View History

2015-12-19 09:26:34 +00:00
# coding: utf-8
2015-04-20 02:12:11 +00:00
2015-12-19 09:26:34 +00:00
from django.db import models
from django.contrib.auth.models import AbstractUser
import time
# from jasset.models import Asset, AssetGroup
2015-04-20 02:12:11 +00:00
class UserGroup(models.Model):
name = models.CharField(max_length=80, unique=True)
comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self):
return self.name
2015-12-19 09:26:34 +00:00
class User(AbstractUser):
2015-04-20 02:12:11 +00:00
USER_ROLE_CHOICES = (
('SU', 'SuperUser'),
2015-12-19 09:26:34 +00:00
('GA', 'GroupAdmin'),
2015-04-20 02:12:11 +00:00
('CU', 'CommonUser'),
)
name = models.CharField(max_length=80)
2015-12-19 09:26:34 +00:00
uuid = models.CharField(max_length=100)
2015-04-20 02:12:11 +00:00
role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU')
group = models.ManyToManyField(UserGroup)
2015-12-19 09:26:34 +00:00
ssh_key_pwd = models.CharField(max_length=200)
# is_active = models.BooleanField(default=True)
# last_login = models.DateTimeField(null=True)
# date_joined = models.DateTimeField(null=True)
2015-04-20 02:12:11 +00:00
def __unicode__(self):
return self.username
2015-12-19 09:26:34 +00:00
class AdminGroup(models.Model):
"""
under the user control group
用户可以管理的用户组或组的管理员是该用户
"""
user = models.ForeignKey(User)
group = models.ForeignKey(UserGroup)
def __unicode__(self):
return '%s: %s' % (self.user.username, self.group.name)
class Document(models.Model):
def upload_to(self, filename):
return 'upload/'+str(self.user.id)+time.strftime('/%Y/%m/%d/', time.localtime())+filename
docfile = models.FileField(upload_to=upload_to)
user = models.ForeignKey(User)