def reply_list_update_random(self, u, q): candidate_users = User.objects.filter(~Q(username=u)).filter(~Q(username=q.questioner)) try: r_list = ReplyList() r_list.answerer = random.choice(candidate_users) r_list.question = q r_list.time_limit_date = datetime.datetime.now() + datetime.timedelta(hours=q.time_limit.hour, minutes=q.time_limit.minute, seconds=q.time_limit.second) return r_list except IndexError: return None
def reply_list_update_random_except(self, users, question): """ 指定されたユーザリストの中からランダムに次の回答ユーザを決定する。 """ if not users: return None r_list = ReplyList() r_list.answerer = random.choice(users) r_list.question = question r_list.time_limit_date = datetime.datetime.now() + datetime.timedelta(hours=question.time_limit.hour, minutes=question.time_limit.minute, seconds=question.time_limit.second) return r_list