def delete(self, *args, **kwargs): """Override delete method to update parent question info.""" question = Question.uncached.get(pk=self.question.id) if question.last_answer == self: answers = question.answers.all().order_by('-created') try: question.last_answer = answers[1] except IndexError: # The question has only one answer question.last_answer = None if question.solution == self: question.solution = None # Delete karma solution action. SolutionAction(user=self.creator, day=self.created).delete() # Delete karma answer action and first answer action if it was first. AnswerAction(user=self.creator, day=self.created).delete() if self.id == question.answers.all().order_by('created')[0].id: FirstAnswerAction(user=self.creator, day=self.created).delete() answers = question.answers.filter(is_spam=False) question.num_answers = answers.count() - 1 question.save() question.clear_cached_contributors() super(Answer, self).delete(*args, **kwargs) update_answer_pages.delay(question)
def delete(self, *args, **kwargs): """Override delete method to update parent question info.""" question = Question.uncached.get(pk=self.question.id) if question.last_answer == self: answers = question.answers.all().order_by('-created') try: question.last_answer = answers[1] except IndexError: # The question has only one answer question.last_answer = None if question.solution == self: question.solution = None # Delete karma solution action. SolutionAction(user=self.creator, day=self.created).delete() # Delete karma answer action and first answer action if it was first. AnswerAction(user=self.creator, day=self.created).delete() if self.id == question.answers.all().order_by('created')[0].id: FirstAnswerAction(user=self.creator, day=self.created).delete() question.num_answers = question.answers.count() - 1 question.save() question.clear_cached_contributors() super(Answer, self).delete(*args, **kwargs) update_answer_pages.delay(question)
def delete(self, *args, **kwargs): """Override delete method to update parent question info.""" question = Question.objects.get(pk=self.question.id) if question.last_answer == self: answers = question.answers.all().order_by('-created') try: question.last_answer = answers[1] except IndexError: # The question has only one answer question.last_answer = None if question.solution == self: question.solution = None answers = question.answers.filter(is_spam=False) question.num_answers = answers.count() - 1 question.save() question.clear_cached_contributors() super(Answer, self).delete(*args, **kwargs) update_answer_pages.delay(question)