我有一个带有 的表单wtform
,我想使用JobItemForm
向我的表单添加一个新表单。已命名。我通过这样的模型添加选择字段数据JobForm
append_entry
JobItemForm
selectField
company
form.jobs[0].company.choices = company_list
现在我append_entry
没有任何选择地使用,我收到一个错误。那么我怎样才能调用append_entry
一些初始数据呢?
class JobItemForm(Form):
company = SelectField(_('company'), description=_('<a href="/education/institute/add/">new company"</a>'))
title = TextField(_('title'), [validators.Length(min=4, max=250)])
date_from = DateField(_("date_from"), format='%Y-%m-%d')
date_to = DateField(_("date_to"), format='%Y-%m-%d')
description = TextAreaField(_('description'))
class JobForm(Form):
jobs = FieldList(FormField(JobItemForm), min_entries=3)
add_job = SubmitField(_('Add job'))
像这样的东西
@mod.route('/edit/', methods=['GET', 'POST'])
@login_required
def edit_job():
"""
edit job
"""
company_list = Company.Company_list()
form_title = "Edit job Form"
if request.method != 'POST':
form = JobForm()
form.jobs[0].company.choices = company_list
return render('form.html', form=form, form_title=form_title)
form = JobForm(request.form)
if form.add_job.data:
new_item_job = form.jobs.append_entry()
new_item_job.company.choices = company_list
return render('form.html', form=form, form_title=form_title)
form.validate
if form.errors != dict():
return render('form.html', form=form, form_title=form_title)
# save data
flash(_("Edit successfully!"))
return render('registration/succesful.html')