12345678910111213141516171819202122232425262728293031 |
- from django.contrib.auth.models import User
- from django.db import models
- # Create your models here.
- from mptt.fields import TreeForeignKey
- from mptt.models import MPTTModel
- class Route(MPTTModel):
- path = models.CharField(max_length=50)
- name = models.CharField(max_length=50)
- alias = models.CharField(max_length=50)
- url = models.CharField(max_length=50)
- parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
- class Meta:
- app_label = "routes" # 指向自己的文件夹,不是项目,是这个模型的
- db_table = "routes" # 定义生成表的名称
- verbose_name = "路由表" # 注解
- verbose_name_plural = "路由表" # 注解
- class Route2User(models.Model):
- user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
- route = models.ForeignKey(Route, on_delete=models.CASCADE, blank=True, null=True)
- class Meta:
- app_label = "routes" # 指向自己的文件夹,不是项目,是这个模型的
- db_table = "Route2User" # 定义生成表的名称
- verbose_name = "用户对应路由关联表" # 注解
- verbose_name_plural = "用户对应路由关联表" # 注解
|