def edit_city(id): ''' Edit City ''' city = City.query.filter_by(id=id).first() form = CityForm(obj=city) if form.validate_on_submit(): try: form.populate_obj(city) db.session.add(city) db.session.commit() flash('Saved successfully', 'success') except: db.session.rollback() flash('Error updating city.', 'danger') return render_template('web/edit_city.html', form=form)
def create_city(): ''' Create city ''' form = CityForm() if form.validate_on_submit(): city = City() form.populate_obj(city) db.session.add(city) try: db.session.commit() flash('City created correctly', 'success') return redirect(url_for('city.cities', **request.args)) except Exception as e: db.session.rollback() flash('Error creating city', 'danger') return render_template('web/create_city.html', form=form)