#-----------------------------------------------------------------
# 自定义管理器
class ZDYManager(models.Manager):
""" 自定义方法 """
def create_book(self,btitle,read):
'''>>>create<<<'''
book = self.model()
book.btitle = btitle
book.bpub_date= date(2000,1,1)
book.bread = read
book.isDelete = 0
book.save()
return book
""" 重写方法 """
def all(self):
'''>>>object.all<<<'''
return super().all().filter(isDelete=False)
# # models.Model 是我们ORM框架里的模型
class BookInfo(models.Model):
btitle = models.CharField(max_length=30) # 最大字符数
# auto_now 标记修改时间 auto_now_add 标记创建时间
bpub_date = models.DateField(auto_now_add=True) # 时间
bread = models.IntegerField(default=0)
bcomment = models.IntegerField(default=0)
isDelete = models.BooleanField(default=False)
hahaha = ZDYManager()
# shell 操作
#
# from booktest.models import BookInfo
# book = BookInfo.hahaha.create_book('雪上飞龙',2)
#-----------------------------------------------------------------
网友评论