I am using SqlAlchemy with Flask and Postgresql. I have a basic insert operation but I would like the behavior of replace/upsert
or on duplicate key update
. Any help would be appreciated.
@auth_blueprint.route('/profile', methods=('GET', 'POST'))
def profile():
try:
session.pop('_flashes', None)
except:
pass
user = Profile.query.filter_by(id=current_user.id).first_or_404()
form = ProfileForm(obj=user)
if form.validate_on_submit():
form.populate_obj(profile)
ins = Profile(
id = current_user.id,
company = form.company.data,
address1 = form.address1.data,
address2 = form.address2.data,
city = form.city.data,
state = form.state.data,
postal_code = form.postal_code.data,
phone = form.phone.data
)
db.session.add(ins)
db.session.commit()
return redirect(url_for('admin.dashboard')) #submit data
return render_template('auth/profile.html', form=form)