models.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. # Create your models here.
  4. from mptt.fields import TreeForeignKey
  5. from mptt.models import MPTTModel
  6. class Route(MPTTModel):
  7. path = models.CharField(max_length=50)
  8. name = models.CharField(max_length=50)
  9. alias = models.CharField(max_length=50)
  10. url = models.CharField(max_length=50)
  11. parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
  12. class Meta:
  13. app_label = "routes" # 指向自己的文件夹,不是项目,是这个模型的
  14. db_table = "routes" # 定义生成表的名称
  15. verbose_name = "路由表" # 注解
  16. verbose_name_plural = "路由表" # 注解
  17. class Route2User(models.Model):
  18. user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
  19. route = models.ForeignKey(Route, on_delete=models.CASCADE, blank=True, null=True)
  20. class Meta:
  21. app_label = "routes" # 指向自己的文件夹,不是项目,是这个模型的
  22. db_table = "Route2User" # 定义生成表的名称
  23. verbose_name = "用户对应路由关联表" # 注解
  24. verbose_name_plural = "用户对应路由关联表" # 注解