2021-11-04 17:35:34 +08:00
|
|
|
from extensions.exceptions import ValidationError
|
|
|
|
from extensions.models import *
|
|
|
|
|
|
|
|
|
|
|
|
class Team(Model):
|
|
|
|
|
|
|
|
number = CharField(max_length=32, unique=True, verbose_name='编号')
|
|
|
|
expiry_time = DateTimeField(verbose_name='到期时间')
|
|
|
|
create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间')
|
2021-11-11 23:58:18 +08:00
|
|
|
enable_auto_stock_in = BooleanField(default=False, verbose_name='启用自动入库')
|
|
|
|
enable_auto_stock_out = BooleanField(default=False, verbose_name='启用自动出库')
|
2021-11-04 17:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
class PermissionType(Model):
|
|
|
|
"""权限类型"""
|
|
|
|
|
|
|
|
name = CharField(max_length=64, verbose_name='类型名称')
|
|
|
|
|
|
|
|
|
|
|
|
class Permission(Model):
|
|
|
|
"""权限"""
|
|
|
|
|
|
|
|
type = ForeignKey('system.PermissionType', on_delete=CASCADE, related_name='permissions', verbose_name='权限类型')
|
|
|
|
name = CharField(max_length=64, verbose_name='权限名称')
|
|
|
|
code = CharField(max_length=64, verbose_name='权限代码')
|
|
|
|
|
|
|
|
|
2021-11-08 17:27:57 +08:00
|
|
|
class Role(Model):
|
2021-11-04 17:35:34 +08:00
|
|
|
"""角色"""
|
|
|
|
|
|
|
|
name = CharField(max_length=64, verbose_name='名称')
|
2021-11-14 02:33:24 +08:00
|
|
|
remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')
|
2021-11-04 17:35:34 +08:00
|
|
|
permissions = ManyToManyField('system.Permission', blank=True, related_name='roles', verbose_name='权限')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='roles')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('name', 'team')]
|
|
|
|
|
|
|
|
|
2021-11-08 17:27:57 +08:00
|
|
|
class User(Model):
|
2021-11-04 17:35:34 +08:00
|
|
|
"""用户"""
|
|
|
|
|
2021-11-06 00:55:40 +08:00
|
|
|
class Sex(TextChoices):
|
|
|
|
"""性别"""
|
|
|
|
|
|
|
|
MAN = ('man', '男')
|
|
|
|
WOMAN = ('woman', '女')
|
|
|
|
|
2021-11-04 23:09:35 +08:00
|
|
|
username = CharField(max_length=32, verbose_name='用户名')
|
2021-11-04 17:35:34 +08:00
|
|
|
password = CharField(max_length=256, verbose_name='密码')
|
|
|
|
name = CharField(max_length=64, verbose_name='名称')
|
2021-11-14 02:33:24 +08:00
|
|
|
phone = CharField(max_length=32, null=True, blank=True, verbose_name='手机号')
|
|
|
|
email = CharField(max_length=256, null=True, blank=True, verbose_name='邮箱')
|
2021-11-06 00:55:40 +08:00
|
|
|
sex = CharField(max_length=32, choices=Sex.choices, verbose_name='性别')
|
2021-11-04 17:35:34 +08:00
|
|
|
roles = ManyToManyField('system.Role', blank=True, related_name='users', verbose_name='角色')
|
|
|
|
is_manager = BooleanField(default=False, verbose_name='管理员状态')
|
|
|
|
is_active = BooleanField(default=True, verbose_name='激活状态')
|
|
|
|
create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间')
|
|
|
|
team = ForeignKey('system.Team', on_delete=CASCADE, related_name='users')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = [('username', 'team')]
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'Team', 'PermissionType', 'Permission', 'Role', 'User',
|
|
|
|
]
|