本文整理汇总了Python中models.Question.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Question.objects方法的具体用法?Python Question.objects怎么用?Python Question.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.objects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: player_questions
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import objects [as 别名]
def player_questions(name):
''' get a relevant question
'''
'''
players = Player.objects(name=name)
if not players:
abort(404)
player = players[0]
'''
questions = Question.objects()
index = int(math.floor(random.random()*len(questions)))
q = questions[index]
return jsonify({
'prompt': q.prompt
, 'response_0': q.possible_responses[0]
, 'response_1': q.possible_responses[1]
, 'response_2': q.possible_responses[2]
, 'response_3': q.possible_responses[3]
, 'classification': q.classification
, 'question_id': str(q.id)
})
示例2: destroy_seed
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import objects [as 别名]
def destroy_seed():
objects = []
objects.extend(Question.objects())
objects.extend(Player.objects())
objects.extend(Answer.objects())
objects.extend(BodyMediaData.objects())
for o in objects:
o.delete()
return 'ouch'
示例3: player_answers
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import objects [as 别名]
def player_answers(name):
players = Player.objects(name=name)
if not players:
abort(404)
player = players[0]
question_id = request.form.get('question_id', '')
response = request.form.get('response', '')
question = Question.objects(id=question_id)[0]
new_answer = Answer(
question = question
, player = player
, data = int(response)
, timestamp = datetime.datetime.utcnow()
)
new_answer.save()
player.update(set__last_answer_time=datetime.datetime.utcnow())
answer_count = Answer.objects(player=player).count()
return jsonify({'status': 'ok', 'answer_count': answer_count})
示例4: seed_questions
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import objects [as 别名]
def seed_questions():
questions = Question.objects()
if questions:
return 'already seeded'
q = Question(
prompt = 'How many times did you wake up last night?'
, possible_responses = ['0', '1', '2', '3']
, classification = 'morning'
)
q.save()
q = Question(
prompt = 'How bad were your asthma symptoms when you woke up this morning?'
, possible_responses = ['not bad at all', 'a little bad', 'somewhat bad', 'very bad']
, classification = 'morning'
)
q.save()
q = Question(
prompt = 'How rested do you feel this morning?'
, possible_responses = ['well rested', 'somewhat', 'a little', 'not at all']
, classification = 'morning'
)
q.save()
q = Question(
prompt = 'How much trouble did you have falling asleep?'
, possible_responses = ['no trouble', 'a little trouble', 'some trouble', 'a lot of trouble']
, classification = 'morning'
)
q.save()
q = Question(
prompt = 'How limited were you in activities because of your asthma?'
, possible_responses = ['not at all', 'a little', 'somewhat', 'a lot']
, classification = 'night'
)
q.save()
q = Question(
prompt = 'How much shortness did you experience because of your asthma?'
, possible_responses = ['none at all', 'a little', 'some', 'a lot']
, classification = 'night'
)
q.save()
q = Question(
prompt = 'How much time did you wheeze today?'
, possible_responses = ['none at all', 'a little of the time', 'some of the time', 'a lot of the time']
, classification = 'night'
)
q.save()
q = Question(
prompt = 'How many times did you use your inhaler today?'
, possible_responses = ['zero', '1-2', '3-4', '5+']
, classification = 'night'
)
q.save()
q = Question(
prompt = 'How much did your asthma affect your exercise today?'
, possible_responses = ['not at all', 'a little', 'somewhat', 'a lot']
, classification = 'night'
)
q.save()
q = Question(
prompt = 'How would you rate your asthma control today?'
, possible_responses = ['1', '2', '3', '4']
, classification = 'night'
)
q.save()
return 'ok'