本文整理汇总了Python中models.Group.update方法的典型用法代码示例。如果您正苦于以下问题:Python Group.update方法的具体用法?Python Group.update怎么用?Python Group.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Group
的用法示例。
在下文中一共展示了Group.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_update
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import update [as 别名]
def admin_update(what, id):
if what == 'specialty':
form = SpecialtyForm()
tmp = Specialty.get_by_id(id)
if form.validate_on_submit():
tmp.long_form = form.long_form.data
tmp.short_form = form.short_form.data
Specialty.update(tmp)
flash(u'Спеціальність успішно оновлено!')
return redirect_back('admin_specialty')
elif request.method == 'POST':
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
else:
form.long_form.data = tmp.long_form
form.short_form.data = tmp.short_form
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
if what == 'subject':
form = SubjectForm()
tmp = Subject.get_by_id(id)
if form.validate_on_submit():
tmp.title = form.title.data
Subject.update(tmp)
flash(u'Предмет успішно оновлено!')
return redirect_back('admin_subject')
elif request.method == 'POST':
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
else:
form.title.data = tmp.title
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
if what == 'group':
form = GroupForm()
form.group_specialty.choices = [(h.id, h.long_form) for h in Specialty.get_all()]
tmp = Group.get_by_id(id)
if form.validate_on_submit():
tmp.group_number = form.group_number.data
tmp.group_course = form.group_course.data
tmp.specialty_id = form.group_specialty.data
Group.update(tmp)
flash(u'Групу упішно оновлено!')
return redirect_back('admin_group')
elif request.method == 'POST':
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
else:
form.group_number.data = tmp.group_number
form.group_course.data = tmp.group_course
form.group_specialty.data = tmp.specialty_id
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
if what == 'lecturer':
form = LecturerForm()
form.lessons.choices = [(h.id, h.title) for h in Subject.get_all()]
tmp = Lecturer.get_by_id(id)
if form.validate_on_submit():
tmp.first_name = form.first_name.data
tmp.middle_name = form.middle_name.data
tmp.last_name = form.last_name.data
Lecturer.update(tmp)
Lessons.add(id, form.lessons.data)
flash(u'Дані викладача успішно оновлено!')
return redirect_back('admin_lecturer')
elif request.method == 'POST':
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)
else:
form.lessons.data = [h.id for h in tmp.subjects]
form.first_name.data = tmp.first_name
form.middle_name.data = tmp.middle_name
form.last_name.data = tmp.last_name
next = get_redirect_target()
return render_template('admin_update.html', form=form, type=what, id=id, next=next)