models.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. # Create your models here.
  4. from mptt.models import MPTTModel
  5. class DailyMptt(MPTTModel):
  6. #verbose_name表示,on_delete父级删除时的处理
  7. parent = models.ForeignKey('self', verbose_name='上级区域', null=True, blank=True, related_name='children', on_delete = models.CASCADE)
  8. title = models.CharField(max_length=50)
  9. content = models.TextField()
  10. create_at = models.DateTimeField(auto_now=True)
  11. create_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE)
  12. son_size = models.IntegerField(default=0)
  13. # def toKeyToVal(self):
  14. def getObject(self, data):
  15. for key, val in data.items():
  16. if hasattr(self, key):
  17. self.__setattr__(key, val)
  18. return self
  19. class MPTTMeta:
  20. order_insertion_by = ['title']#自然顺序
  21. # 权限表
  22. class Role(models.Model):
  23. title = models.CharField(max_length=32)
  24. permissions = models.ManyToManyField('Permission')
  25. def __str__(self):
  26. return self.title
  27. #菜单表
  28. class menu(models.Model):
  29. title = models.CharField(max_length=32)
  30. url = models.CharField(max_length=32)
  31. def __str__(self):
  32. return self.title