models.py 863 B

1234567891011121314151617181920212223
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. #路由表
  4. from mptt.models import MPTTModel
  5. #路由表
  6. class Route(MPTTModel):
  7. name = models.CharField('name', max_length=80)
  8. path = models.CharField('name', max_length=80)
  9. url = models.CharField('name', max_length=80)
  10. parent = models.ForeignKey('self', verbose_name='上级', null=True, blank=True, related_name='pid', on_delete = models.CASCADE)
  11. class UserRoute(models.Model):
  12. route = models.ForeignKey('Route', verbose_name='菜单', null=False, blank=False, related_name='ur_route',
  13. on_delete=models.CASCADE)
  14. user = models.ForeignKey(User, verbose_name='用户', null=False, blank=False, related_name='ur_user',
  15. on_delete=models.CASCADE)
  16. class Meta:
  17. unique_together = ('user', 'route')