本文整理汇总了Python中forms.QuestionForm.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm.setData方法的具体用法?Python QuestionForm.setData怎么用?Python QuestionForm.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.QuestionForm
的用法示例。
在下文中一共展示了QuestionForm.setData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: game_modify
# 需要导入模块: from forms import QuestionForm [as 别名]
# 或者: from forms.QuestionForm import setData [as 别名]
def game_modify(request, gameid=None, qmod=False):
question_form = None
inst = None
if gameid != "new":
inst = Game.objects.get(id=gameid)
questions = Question.objects.all()
question_form = QuestionForm()
fields = {}
our_questions = inst.questionforgame_set
for question in questions:
fields["%s" % question.id] = BooleanField(label=question.uniq_name, required=False, widget=CheckboxInput)
fields["%s_required" % question.id] = BooleanField(label=" %s povinne" % question.uniq_name, required=False, widget=CheckboxInput)
if question in [ que.question for que in our_questions.all() ]:
fields["%s" % question.id].initial = True
if our_questions.get(question=question).required:
fields["%s_required" % question.id].initial = True
question_form.setFields(fields)
if request.method == 'POST':
if qmod:
form = QuestionForm()
fields={}
for question in Question.objects.all():
fields["%s" % question.id] = BooleanField(label=question.uniq_name, required=False, widget=CheckboxInput)
fields["%s_required" % question.id] = BooleanField(label=" %s povinne" % question.uniq_name, required=False, widget=CheckboxInput)
form.setFields(fields)
form.setData(request.POST)
form.validate(request.POST)
if form.is_valid():
form.save(gameid)
return HttpResponseRedirect('/admin/games/')
else:
form = GameForm(request.POST, instance=inst)
print "We should end here"
if form.is_valid():
form.save()
return HttpResponseRedirect('/admin/games/')
else:
form = GameForm(instance=inst)
return render_to_response('admin/gameform.html',
{'form': form, 'gameid': gameid,
'menuitems' : createMenuItems(),
'user' : request.user,
'title' : "Editace hry",
'questions' : question_form})