コード例 #1
0
    def save(self, *args, **kwargs):
        """Send the vote_changed signal if this is a new object or if
        the vote has changed since last save.
        """
        newly_created_vote = True if not self.pk else False

        super(Vote, self).save(*args, **kwargs)

        # Send signal in post_save.
        if newly_created_vote:
            vote_changed.send(
                self.__class__,
                instance=self,
                old_vote=None,
                new_vote=self.vote
            )
            self._cached_vote = self.vote

        elif self.vote != self._cached_vote:
            vote_changed.send(
                self.__class__,
                instance=self,
                old_vote=self._cached_vote,
                new_vote=self.vote
            )
            self._cached_vote = self.vote
コード例 #2
0
def send_vote_changed_on_delete(sender, instance, **kwargs):
    """Send vote_changed on a hard delete of a vote."""
    vote_changed.send(
        sender,
        instance=instance,
        old_vote=instance._cached_vote,
        new_vote=None
    )