重定义models mananger方法
Models:
def AssetManager(models.Manager):
def all(self):
return super(AssetManager,self).exclude(type='server')
def Asset_count(self):
return self.all().count()
def Asset(models.Model):
assetno=models.CharField(max_length=32)
type=models.CharField(max_length=32)
model=models.CharField(max_length=32)
objects=AssetManager()
def content(self):
return self.assetno+self.type
Views:
asset_count=models.Asset.objects.Asset_count()
asset_list=models.Asset.objects.all()# 默认是查找所的有asset但重新自定义后只查找资产类型不是server的所有资产