Exemple #1
0
def create_post(db: Session, post: PostCreate):
    db_post = models.Post(title=post.title, content=post.content)
    db.add(db_post)
    db.commit()
    db.refresh(db_post)

    return db_post
Exemple #2
0
def update_post(db: Session, post: Post):
    db_post = db.query(models.Post).get(post.id)
    post_dict = get_dict_from_model(post)
    for key, value in post_dict.items():
        setattr(db_post, key, value)
    db.commit()
    db.refresh(db_post)

    return db_post