def create_post(post_in: PostIn): author = get_user(user_name=post_in.author) if author: post = Post(author=post_in.author, title=post_in.title, body=post_in.body) try: post.save() return post except: return False
def create_or_get_post(user_id, title, text): session = Session() post = session.query(Post).filter_by(title=title).first() if not post: post = Post(title=title, text=text, user_id=user_id) session.add(post) session.commit() post_id = post.id session.close() return post_id