-class Question(QandA):
- accepted_answer = models.OneToOneField('Answer', null=True, related_name="question_accepting")
- closed = models.BooleanField(default=False)
- closed_by = models.ForeignKey(User, null=True, blank=True, related_name='closed_questions')
- closed_at = models.DateTimeField(null=True, blank=True)
- close_reason = models.SmallIntegerField(choices=CLOSE_REASONS, null=True, blank=True)
- subscribers = models.ManyToManyField(User, related_name='subscriptions', through='QuestionSubscription')
-
- # Denormalised data
- answer_count = models.PositiveIntegerField(default=0)
- view_count = models.IntegerField(default=0)
- favourite_count = models.IntegerField(default=0)
- last_activity_at = models.DateTimeField(default=datetime.datetime.now)
- last_activity_by = models.ForeignKey(User, related_name='last_active_in_questions', null=True)
-
- favorited_by = models.ManyToManyField(User, through='FavoriteQuestion', related_name='favorite_questions')
-
- class Meta(QandA.Meta):
- db_table = u'question'
+class QuestionManager(NodeManager):
+ def search(self, keywords):
+ return False, self.filter(models.Q(title__icontains=keywords) | models.Q(body__icontains=keywords))
+
+class Question(Node):
+ class Meta(Node.Meta):
+ proxy = True
+
+ answer_count = DenormalizedField("children", ~models.Q(state_string__contains="(deleted)"), node_type="answer")
+ favorite_count = DenormalizedField("actions", action_type="favorite", canceled=False)
+
+ friendly_name = _("question")
+ objects = QuestionManager()