def change_fave(self, user): fave = Fave.get_unique(ref_type=self.__class__.__name__, ref_pk=self.id, user=user) if fave is None: fave = Fave.create(ref_type=self.__class__.__name__, ref_pk=self.id, user=user) fave.save() self.popularity += 5 else: fave.delete() self.popularity = max(0, self.popularity - 5) self.save()
def faves(self): return Fave.find_by_ref(ref_type=self.__class__.__name__, ref_pk=self.id)