def save(self, no_update=False, no_notify=False, *args, **kwargs): """ Override save method to update question info and take care of updated. """ new = self.id is None if new: page = self.question.num_answers / constants.ANSWERS_PER_PAGE + 1 self.page = page else: self.updated = datetime.now() super(Answer, self).save(*args, **kwargs) if new: self.question.num_answers = self.question.answers.count() self.question.last_answer = self self.question.save(no_update) if not no_notify: # Avoid circular import, events.py imports Question from questions.events import QuestionReplyEvent QuestionReplyEvent(self).fire(exclude=self.creator)
def save(self, update=True, no_notify=False, *args, **kwargs): """ Override save method to update question info and take care of updated. """ new = self.id is None if new: page = self.question.num_answers / constants.ANSWERS_PER_PAGE + 1 self.page = page else: self.updated = datetime.now() self.clear_cached_html() super(Answer, self).save(*args, **kwargs) if new: # Occasionally, num_answers seems to get out of sync with the # actual number of answers. This changes it to pull from # uncached on the off chance that fixes it. Plus if we enable # caching of counts, this will continue to work. self.question.num_answers = Answer.uncached.filter( question=self.question).count() self.question.last_answer = self self.question.save(update) self.question.clear_cached_contributors() if not no_notify: # Avoid circular import: events.py imports Question. from questions.events import QuestionReplyEvent QuestionReplyEvent(self).fire(exclude=self.creator)