12345678910111213141516171819202122232425262728 |
- 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']#自然顺序
|