models.py 905 B

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