Python Sqlalchemy根据提供的ID插入或更新完整记录

Python Sqlalchemy根据提供的ID插入或更新完整记录,python,flask,flask-sqlalchemy,Python,Flask,Flask Sqlalchemy,在Python Alchemy中,我有一个对象,它要么是新记录,要么是对现有记录的更新。在更新的情况下,它始终是整行(无增量)。条件是存在提供的ID。我需要执行的If-Else树是什么 现在我只有插页 # This object needs to be used at all times, the only difference is INSERT vs. UPDATE for an ID agreement = AgreementT( start_date=fo

在Python Alchemy中,我有一个对象,它要么是新记录,要么是对现有记录的更新。在更新的情况下,它始终是整行(无增量)。条件是存在提供的ID。我需要执行的If-Else树是什么

现在我只有插页

# This object needs to be used at all times, the only difference is INSERT vs. UPDATE for an ID
agreement = AgreementT(
                start_date=form.get('startDate', None), 
                end_date=form.get('expirationDate', None), 
                # etc.
            )
db_session.add(agreement)
db_session.commit()
你是不是想做一个实验?