本文整理汇总了Python中models.Answer.answer方法的典型用法代码示例。如果您正苦于以下问题:Python Answer.answer方法的具体用法?Python Answer.answer怎么用?Python Answer.answer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Answer
的用法示例。
在下文中一共展示了Answer.answer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import answer [as 别名]
def save(self, commit=True):
test = super(TestAdminForm, self).save(False)
file = self.cleaned_data['file']
questions_count = self.cleaned_data['questions_count']
if file:
test_name = test.name
test.save()
AnswerResult.objects.filter(answer__question__test=test).delete()
AnswerChoice.objects.filter(question__test=test).delete()
TestPass.objects.filter(test=test).delete()
Answer.objects.filter(question__test=test).delete()
Question.objects.filter(test=test).delete()
questions = parser(file)
count = 0
cur_test = test
for i, question in enumerate(questions):
count += 1
q = Question(test=cur_test, question=question['question'])
if question['text_answer']:
q.text_answer = question['text_answer']
q.save()
else:
q.save()
for answer in question['answers']:
a = Answer(question=q)
a.answer = answer['text']
a.correct = answer['correct']
a.save()
if questions_count and count >= questions_count:
if (len(questions) - i) >= questions_count:
cur_test.name = '%s [%s-%s]' % (test_name, i+1-count, i+1)
cur_test.save()
cur_test = copy(test)
cur_test.pk = None
cur_test.save()
else:
cur_test.name = '%s [%s-%s]' % (test_name, i+1-count, len(questions))
cur_test.save()
count = 0
return test