Reputation: 406
I'm trying to update a record in my db. The form renders well and receives the input from the views.py. After submission the redirect works, but the database is not updated with the form data. What am I missing?
class Party(db.Model):
id = db.Column(db.Integer, primary_key=True)
party_name = db.Column(db.String(64))
@main.route('/edit-party/<int:id>', methods=['GET', 'POST'])
def edit_party(id):
party = Party.query.filter_by(id=id).first_or_404()
form = PartyForm()
form.party_name.data = party.party_name
if form.validate_on_submit():
party.party_name = form.party_name.data
db.session.add(party)
return redirect('parties')
return render_template('edit.html', form=form)
Upvotes: 0
Views: 35
Reputation: 585
You are wiping out your updates before updating. It actually updates the DB, but form.party_name.data = party.party_name
has overwritten your new data.
Upvotes: 1