diff options
Diffstat (limited to 'askbot/models/question.py')
-rw-r--r-- | askbot/models/question.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/askbot/models/question.py b/askbot/models/question.py index 265d9138..a740aac2 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -187,15 +187,22 @@ class QuestionManager(models.Manager): #todo: maybe this must be a query set method, not manager method def get_question_and_answer_contributors(self, question_list): answer_list = [] - question_list = list(question_list)#important for MySQL, b/c it does not support + #question_list = list(question_list)#important for MySQL, b/c it does not support from askbot.models.answer import Answer - answer_list = Answer.objects.filter(question__in = question_list) - contributors = User.objects.filter( - models.Q(questions__in=question_list) \ - | models.Q(answers__in=answer_list) - ).distinct() - contributors = list(contributors) - random.shuffle(contributors) + q_id = list(question_list.values_list('id', flat=True)) + a_id = list(Answer.objects.filter(question__in=q_id).values_list('id', flat=True)) + u_id = set(self.filter(id__in=q_id).values_list('author', flat=True)) + u_id = u_id.union( + set(Answer.objects.filter(id__in=a_id).values_list('author', flat=True)) + ) + contributors = User.objects.filter(id__in=u_id).order_by('?') + #print contributors + #could not optimize this query with indices so it was split into what's now above + #contributors = User.objects.filter( + # models.Q(questions__in=question_list) \ + # | models.Q(answers__in=answer_list) + # ).distinct() + #contributors = list(contributors) return contributors def get_author_list(self, **kwargs): |