我有一个订单。我不想一次处理一个订单,而是想复制表格并一次处理所有表格。我已经尝试过FormField,但是无法处理它。
class OrderForm(Form):
date = DateField('Date',validators=[DataRequired()])
code = StringField('Order Code',validators=[DataRequired()])
item = QuerySelectField('Item',query_factory=items,get_label='code', allow_blank=False,validators=[DataRequired()])
season = QuerySelectField('Season',query_factory=seasons,get_label='code', allow_blank=False,validators=[DataRequired()])
qty = IntegerField('Quantity',validators=[DataRequired()])
unit = QuerySelectField('Units',query_factory=units,get_label='code', allow_blank=False,validators=[DataRequired()])
customer = QuerySelectField('Customer',query_factory=customers,get_label='name', allow_blank=False,validators=[DataRequired()])
我尝试了此表单字段,但无法处理
class ItemForm(Form):
sample_item = FormField(OrderForm)
我的观点:
def sample_order_details(pk):
title = "Sample Order Details"
if 'email' in session:
user = Admin.query.filter_by(email=session['email']).first()
order = SampleOrder.query.filter_by(code=pk).first()
items = SampleOrderItem.query.filter_by(order_code=pk).all()
if user is not None:
form = OrderForm(order_code=pk)
if request.method == 'POST':
if form.validate() == False:
return render_template('order/sample_order_details.html',
name=sample_order_details,
user=user,
title=title,
form=form,
order=order,
items=items
)
else:
newsampleitem = SampleOrderItem(
form.item_code.data,
form.season_code.data,
form.qty.data,
form.unit_code.data,
form.order_code.data,
)
db.session.add(newsampleitem)
db.session.commit()
print(newsampleitem)
code = form.order_code.data
return redirect(url_for('order.sample_order_details', pk=code))
else:
return render_template('order/sample_order_details.html',
name=sample_order_details,
form=form,
title=title,
user=user,
order=order,
items=items
)
else:
return redirect('index')
else:
return redirect('admin.login')