2016-12-20 15:06:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-11-23 06:08:01 +00:00
|
|
|
|
2022-12-09 05:05:34 +00:00
|
|
|
from django.db import models
|
2016-12-20 16:43:52 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2022-12-09 05:05:34 +00:00
|
|
|
from common.utils import lazyproperty
|
2022-12-20 12:23:42 +00:00
|
|
|
from orgs.mixins.models import JMSOrgBaseModel
|
2018-07-13 16:47:21 +00:00
|
|
|
|
2016-12-20 16:43:52 +00:00
|
|
|
__all__ = ['UserGroup']
|
|
|
|
|
|
|
|
|
2022-12-20 12:23:42 +00:00
|
|
|
class UserGroup(JMSOrgBaseModel):
|
2018-07-16 06:47:06 +00:00
|
|
|
name = models.CharField(max_length=128, verbose_name=_('Name'))
|
2016-12-20 16:43:52 +00:00
|
|
|
|
2017-12-04 12:15:47 +00:00
|
|
|
def __str__(self):
|
2016-12-20 16:43:52 +00:00
|
|
|
return self.name
|
|
|
|
|
2019-12-16 08:53:29 +00:00
|
|
|
@lazyproperty
|
|
|
|
def users_amount(self):
|
|
|
|
return self.users.count()
|
|
|
|
|
2016-12-20 16:43:52 +00:00
|
|
|
class Meta:
|
2016-12-21 16:36:31 +00:00
|
|
|
ordering = ['name']
|
2022-12-20 12:23:42 +00:00
|
|
|
unique_together = [('org_id', 'name'), ]
|
2018-03-05 04:59:14 +00:00
|
|
|
verbose_name = _("User group")
|
2016-12-20 16:43:52 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def initial(cls):
|
2017-03-04 08:38:26 +00:00
|
|
|
default_group = cls.objects.filter(name='Default')
|
|
|
|
if not default_group:
|
|
|
|
group = cls(name='Default', created_by='System', comment='Default user group')
|
|
|
|
group.save()
|
|
|
|
else:
|
|
|
|
group = default_group[0]
|
2016-12-20 16:43:52 +00:00
|
|
|
return group
|