1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- from django.contrib.auth.models import User
- from django.db import models
- # Create your models here.
- from mptt.models import MPTTModel
- class DailyMptt(MPTTModel):
- #verbose_name表示,on_delete父级删除时的处理
- parent = models.ForeignKey('self', verbose_name='上级区域', null=True, blank=True, related_name='children', on_delete = models.CASCADE)
- title = models.CharField(max_length=50)
- content = models.TextField()
- create_at = models.DateTimeField(auto_now=True)
- create_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE)
- son_size = models.IntegerField(default=0)
- # def toKeyToVal(self):
- def getObject(self, data):
- for key, val in data.items():
- if hasattr(self, key):
- self.__setattr__(key, val)
- return self
- class MPTTMeta:
- order_insertion_by = ['title']#自然顺序
- # 权限表
- class Role(models.Model):
- title = models.CharField(max_length=32)
- permissions = models.ManyToManyField('Permission')
- def __str__(self):
- return self.title
- #菜单表
- class menu(models.Model):
- title = models.CharField(max_length=32)
- url = models.CharField(max_length=32)
- def __str__(self):
- return self.title
|