models.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from django.contrib.auth.base_user import AbstractBaseUser
  2. from django.contrib.auth.models import PermissionsMixin, AbstractUser
  3. from django.db import models
  4. # Create your models here.
  5. class Permission(models.Model):
  6. id = models.CharField(max_length=128, primary_key=True, unique=True, verbose_name='权限ID',
  7. default="TestLaboratory_V1_Permission_1")
  8. name = models.CharField(max_length=25, verbose_name='权限名')
  9. url = models.URLField(max_length=125, null=True, blank=True, verbose_name='URL')
  10. # get, post, put, delete
  11. method = models.CharField(max_length=20, null=True, verbose_name='方法')
  12. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  13. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  14. delete = models.BooleanField(default=False)
  15. def __str__(self):
  16. return self.name
  17. class Meta:
  18. verbose_name = '权限'
  19. verbose_name_plural = verbose_name
  20. db_table = 'permission'
  21. class Role(models.Model):
  22. id = models.CharField(max_length=128, primary_key=True, unique=True, verbose_name='角色ID',
  23. default='TestLaboratory_V1_Role_1')
  24. name = models.CharField(max_length=25, unique=True, verbose_name='角色名')
  25. permissions = models.ManyToManyField(Permission, blank=True, verbose_name='权限信息')
  26. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  27. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  28. delete = models.BooleanField(default=False)
  29. def __str__(self):
  30. return self.name
  31. class Meta:
  32. verbose_name = '角色'
  33. verbose_name_plural = verbose_name
  34. db_table = 'role'
  35. class User(models.Model):
  36. id = models.CharField(max_length=128, unique=True, primary_key=True, verbose_name='用户编号',
  37. default='TestLaboratory_V1_User_1')
  38. username = models.CharField(max_length=30, unique=True, verbose_name='用户名')
  39. name = models.CharField(max_length=20, verbose_name='姓名')
  40. password = models.CharField(max_length=60, default='123456', verbose_name='密码')
  41. tel = models.CharField(max_length=20, verbose_name='联系方式')
  42. identify = models.IntegerField(verbose_name='身份信息')
  43. roles = models.ManyToManyField(Role, blank=True, verbose_name='角色信息')
  44. # group = models.CharField(max_length=128, default='默认分组', verbose_name='分组')
  45. create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
  46. update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
  47. is_login = models.BooleanField(default=False)
  48. delete = models.BooleanField(default=False)
  49. def __str__(self):
  50. return self.username
  51. class Meta:
  52. verbose_name = '用户'
  53. verbose_name_plural = verbose_name
  54. db_table = 'user'