本文整理汇总了Python中models.Order.subject_id方法的典型用法代码示例。如果您正苦于以下问题:Python Order.subject_id方法的具体用法?Python Order.subject_id怎么用?Python Order.subject_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Order
的用法示例。
在下文中一共展示了Order.subject_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import subject_id [as 别名]
def order():
if 'username' not in session:
return redirect(url_for('login'))
form = forms.OrderForm(formdata=request.form)
form.category.choices = [(c.id, c.name) for c in Category.query.filter_by(subject_id=form.subject.data)]
if ('0', 'Select...') not in form.subject.choices:
form.subject.choices.insert(0, ('0', 'Select...'))
if request.method == 'POST' and form.validate():
new_order = Order()
new_order.title = form.title.data
new_order.user_id = session['user_id']
new_order.subject_id = form.subject.data
new_order.category_id = form.category.data
new_order.os_id = form.os.data
new_order.details = form.details.data
new_order.deadline = form.deadline.data
new_order.explanations = form.explanations.data
db.session.add(new_order)
db.session.commit()
files = request.files.getlist('file[]')
order_files = []
for f in files:
if f.filename:
ext = f.filename.split('.')[-1]
name = str(uuid.uuid4()) + '.' + ext
path = os.path.join(app.config['FILE_UPLOAD_PATH'], name)
f.save(path)
of = File()
of.order_id = new_order.id
of.name = f.filename
of.local_name = name
order_files.append(of)
for of in order_files:
db.session.add(of)
db.session.commit()
flash('Order submitted :)', _CATEGORY_MESSAGE)
return redirect(url_for('profile'))
return render_template('order.html', form=form)