models.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. title = models.CharField(max_length=50, null=True)
  25. url = models.CharField(max_length=50)
  26. parent = TreeForeignKey('self', blank=True, null=True, on_delete=models.CASCADE)
  27. class Meta:
  28. verbose_name = '前端菜单'
  29. verbose_name_plural = '前端菜单列表'
  30. class GroupRouterMenu(Model):
  31. """
  32. 前端菜单的权限与角色绑定
  33. """
  34. group = models.ForeignKey(Group, blank=True, null=True, on_delete=models.CASCADE)
  35. menu = models.ForeignKey(RouterMenu, blank=True, null=True, on_delete=models.CASCADE)
  36. class Meta:
  37. verbose_name = '前端菜单与角色的中间表'
  38. verbose_name_plural = '前端菜单和角色的中间表列表'