def query_by_entity_uid(idd, kind=''): if kind == '': return g_Post2Tag.select().join(g_Tag).where( (g_Post2Tag.post == idd) & (g_Tag.kind != 'z')).order_by( g_Post2Tag.order) else: return g_Post2Tag.select().join(g_Tag).where( (g_Tag.kind == kind) & (g_Post2Tag.post == idd)).order_by( g_Post2Tag.order)
def get_app_relations(app_id, num=20, kind='1'): ''' The the related infors. ''' info_tag = MInfor2Catalog.get_first_category(app_id) if info_tag: return g_Post2Tag.select().join( g_Post).where((g_Post2Tag.tag == info_tag.tag.uid) & (g_Post.kind == kind)).order_by( peewee.fn.Random()).limit(num) else: return g_Post2Tag.select().join(g_Post).where( g_Post.kind == kind).order_by(peewee.fn.Random()).limit(num)
def query_by_post(postid): ''' Query records by post. :param postid: :return: ''' return g_Post2Tag.select().where(g_Post2Tag.post == postid).order_by( g_Post2Tag.order)
def update_count(cat_id): ''' Update the count of certain category. :param cat_id: :return: ''' entry2 = g_Tag.update(count=g_Post2Tag.select().where( g_Post2Tag.tag == cat_id).count()).where(g_Tag.uid == cat_id) entry2.execute()
def __get_by_info(post_id, catalog_id): recs = g_Post2Tag.select().where((g_Post2Tag.post == post_id) & (g_Post2Tag.tag == catalog_id)) if recs.count() == 1: return recs.get() elif recs.count() > 1: # return the first one, and delete others. idx = 0 out_rec = None for rec in recs: if idx == 0: out_rec = rec else: entry = g_Post2Tag.delete().where( g_Post2Tag.uid == rec.uid) entry.execute() idx += idx return out_rec.get() else: return None
def get_by_info(post_id, catalog_id): tmp_recs = g_Post2Tag.select().join(g_Tag).where( (g_Post2Tag.post == post_id) & (g_Post2Tag.tag == catalog_id) & (g_Tag.kind == 'z')) if tmp_recs.count() > 1: ''' 如果多于1个,则全部删除 ''' idx = 0 out_rec = None for tmp_rec in tmp_recs: if idx == 0: out_rec = tmp_rec else: entry = g_Post2Tag.delete().where( g_Post2Tag.uid == tmp_rec.uid) entry.execute() idx += 1 return out_rec elif tmp_recs.count() == 1: return tmp_recs.get() else: return None
def get_by_uid(idd, kind='z'): return g_Post2Tag.select().join(g_Tag).where((g_Post2Tag.post == idd) & (g_Tag.kind == 'z'))
def query_count(uid): return g_Post2Tag.select().where(g_Post2Tag.tag == uid).count()
def query_count(): recs = g_Post2Tag.select(g_Post2Tag.tag, peewee.fn.COUNT( g_Post2Tag.tag).alias('num')).group_by( g_Post2Tag.tag) return recs
def query_by_catid(catid): return g_Post2Tag.select().where(g_Post2Tag.tag == catid)
def count_of_certain_category(cat_id): return g_Post2Tag.select().where(g_Post2Tag.tag == cat_id).count()