示例#1
0
 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()
示例#2
0
 def faves(self):
     return Fave.find_by_ref(ref_type=self.__class__.__name__, ref_pk=self.id)