models.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.contrib.auth.models import User, Group
  2. from django.db.models import Model
  3. from mptt.fields import TreeForeignKey
  4. from mptt.models import MPTTModel
  5. from django.db import models
  6. class Menu(MPTTModel):
  7. name = models.CharField(max_length=100)
  8. config = models.TextField()
  9. create_at = models.DateTimeField(auto_now_add=True)
  10. create_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE)
  11. parent = TreeForeignKey('self', blank=True, null=True, on_delete=models.CASCADE)
  12. code = models.CharField(max_length=100)
  13. class Meta:
  14. app_label = 'basic'
  15. db_table = 'basic_menu'
  16. verbose_name = '报表菜单'
  17. verbose_name_plural = '报表菜单列表'
  18. class RouterMenu(MPTTModel):
  19. """
  20. 前端路由备份,用作中间表做权限
  21. """
  22. name = models.CharField(max_length=50)
  23. path = models.CharField(max_length=50)
  24. url = models.CharField(max_length=50)
  25. parent = TreeForeignKey('self', blank=True, null=True, on_delete=models.CASCADE)
  26. class Meta:
  27. verbose_name = '前端菜单'
  28. verbose_name_plural = '前端菜单列表'
  29. class GroupRouterMenu(Model):
  30. """
  31. 前端菜单的权限与角色绑定
  32. """
  33. group = models.ForeignKey(Group, blank=True, null=True, on_delete=models.CASCADE)
  34. menu = models.ForeignKey(RouterMenu, blank=True, null=True, on_delete=models.CASCADE)
  35. class Meta:
  36. verbose_name = '前端菜单与角色的中间表'
  37. verbose_name_plural = '前端菜单和角色的中间表列表'