def update_activity(aid): activity = ActivityInfo.query.filter_by(id=aid).first_or_404() activity_form = ActivityForm(obj=activity) if request.method == 'POST' and activity_form.validate: activity_form.populate_obj(activity) db.session.commit() flash(u'活动信息更新成功!') return render_template('/admin/activity_update.html', form=activity_form)
def add_activity(): activity_form = ActivityForm() if request.method == 'POST' and activity_form.validate: # my_filename = secure_filename(activity_form.photo.data.filename) # activity_form.photo.data.save(UPLOAD_IMAGE_PATH + my_filename) activity = ActivityInfo() activity_form.populate_obj(activity) # activity.photo = 'static/user_image/' + my_filename activity.photo = '' db.session.add(activity) db.session.commit() flash(u'活动信息添加成功!') return render_template('/admin/activity_add.html', form=activity_form)