def get_all_img(): """ 获取所有图片 :return: """ imgs = session.query(Img).order_by(Img.upload_time.desc()).all() return imgs
def get_comment_by(post_id): """ 获取图片相关评论 :param post_id: :return: """ comments = session.query(Comment).filter_by(img_id = post_id).all() return comments
def count_likes(img): """ 获取图片的受喜欢的数 :param img: :return: """ counts = session.query(Like).filter_by(likeimg_id = img.id).count() return counts
def get_img_by(post_id): """ 获取具体的图片信息 :param post_id: :return: """ img = session.query(Img).filter_by(id=post_id).first() return img
def get_like_imgs(user): """ 获取用户喜欢的图片 :param user: :return: """ # user = session.query(Like).filter_by(user_id = username).all() like_imgs = session.query(Img).filter(Like.user_id==user.id,Img.id==Like.likeimg_id,Img.user_id!=user.id).all() return like_imgs
def add_img(username,image_url,thumb_url): """ 保存用户上传的图片信息 :return: """ user = session.query(User).filter_by(username=username).first() save_img = Img(image_url=image_url,thumb_url=thumb_url,user=user) session.add(save_img) session.commit() return save_img
def get_img_from(username): """ 根据用户获取用户上传的图片 :param username: :return: """ user = session.query(User).filter_by(username=username).first() if user: return user.imgs else: return []
def get_user(username): user = session.query(User).filter_by(username=username).first() return user