def create_vip_perm_relations(): '''创建 Vip 和 Permission 的关系''' # 获取 VIP vip1 = Vip.get(level=1) vip2 = Vip.get(level=2) vip3 = Vip.get(level=3) # 获取权限 vipflag = Permission.get(name='vipflag') superlike = Permission.get(name='superlike') rewind = Permission.get(name='rewind') anylocation = Permission.get(name='anylocation') unlimit_like = Permission.get(name='unlimit_like') show_liked_me = Permission.get(name='show_liked_me') # 给 VIP 1 分配权限 VipPermRelation.get_or_create(vip_id=vip1.id, perm_id=vipflag.id) VipPermRelation.get_or_create(vip_id=vip1.id, perm_id=superlike.id) # 给 VIP 2 分配权限 VipPermRelation.get_or_create(vip_id=vip2.id, perm_id=vipflag.id) VipPermRelation.get_or_create(vip_id=vip2.id, perm_id=superlike.id) VipPermRelation.get_or_create(vip_id=vip2.id, perm_id=rewind.id) # 给 VIP 3 分配权限 VipPermRelation.get_or_create(vip_id=vip3.id, perm_id=vipflag.id) VipPermRelation.get_or_create(vip_id=vip3.id, perm_id=superlike.id) VipPermRelation.get_or_create(vip_id=vip3.id, perm_id=rewind.id) VipPermRelation.get_or_create(vip_id=vip3.id, perm_id=anylocation.id) VipPermRelation.get_or_create(vip_id=vip3.id, perm_id=unlimit_like.id) VipPermRelation.get_or_create(vip_id=vip3.id, perm_id=show_liked_me.id)
def create_vip_perm_relations(): """创建vip 和 permission的关系""" # 获取vip vip1 = Vip.get(level=1) vip2 = Vip.get(level=2) vip3 = Vip.get(level=3) # 获取权限 vipflag = Permission.get(name='vipflag') superlike = Permission.get(name='superlike') rewind = Permission.get(name='rewind') anylocation = Permission.get(name='anylocation') unlimit_like = Permission.get(name='unlimit_like') show_like_me = Permission.get(name='show_like_me') # 给vip1 分配权限 VipPermission.get_or_create(vip_id=vip1.id, perm_id=vipflag.id) VipPermission.get_or_create(vip_id=vip1.id, perm_id=superlike.id) # 给vip2 分配权限 VipPermission.get_or_create(vip_id=vip2.id, perm_id=vipflag.id) VipPermission.get_or_create(vip_id=vip2.id, perm_id=superlike.id) VipPermission.get_or_create(vip_id=vip2.id, perm_id=rewind.id) # 给vip3 分配权限 VipPermission.get_or_create(vip_id=vip3.id, perm_id=vipflag.id) VipPermission.get_or_create(vip_id=vip3.id, perm_id=superlike.id) VipPermission.get_or_create(vip_id=vip3.id, perm_id=rewind.id) VipPermission.get_or_create(vip_id=vip3.id, perm_id=anylocation.id) VipPermission.get_or_create(vip_id=vip3.id, perm_id=unlimit_like.id) VipPermission.get_or_create(vip_id=vip3.id, perm_id=show_like_me.id)
def vip(self): # 获取指定id的vip if not hasattr(self, '_vip'): self._vip = Vip.get( id=self.vip_id ) # user.vip_id对应的是Vip表的primery_key(id)所以vip_id default = 1对应Vip表中的level是0 return self._vip
def vip(self): """ 用户 vip 信息 :return: """ if not hasattr(self, '_vip'): self._vip = Vip.get(id=self.vip_id) return self._vip
def vip(self): if not hasattr(self, '_vip'): self._vip = Vip.get(id=self.vip_id) return self._vip
def vip(self): """用户对应的vip对象""" if not hasattr(self, '_vip'): self._vip = Vip.get(pk=self.vip_id) return self._vip
def vip(self): '''用户会员''' return Vip.get(id=self.vip_id)
def init_vip(): for i in range(4): vip, _ = Vip.get_or_create(name='%d 级会员' % i, level=i, price=i * 5.0) print('create %s' % vip.name)
def vip(self): '''用户对应的 VIP''' if not hasattr(self, '_vip'): self._vip = Vip.get(id=self.vip_id) return self._vip
def vip(self): '''用户对应的 VIP''' if not hasattr(self, '_vip'): # 检查是否创建过_vip # 动态为self添加 _vip属性 self._vip, _ = Vip.get(id=self.id) return self._vip
def get_vip(pk): return Vip.get(int(pk) + 1)
def update_vip_cache(): Vip.create_cache() VipReward.create_cache()
def get_vips(): return Vip.get_all_list()
def init_vip(): """初始化vip""" for i in range(4): vip, _ = Vip.get_or_create(name='会员-%d' % i, level=i, price=i * 5.0) print('create %s' % vip.name)