def change_fan(self, user): fan = Fan.get_unique(ref_type=self.__class__.__name__, ref_pk=self.id, user=user) if fan is None: fan = Fan.create_fan(ref_type=self.__class__.__name__, ref_pk=self.id, user=user) fan.save() self.popularity += 1 self.resto.popularity += 1 else: fan.delete() self.popularity = max(0, self.popularity - 1) self.resto.popularity = max(0, self.resto.popularity - 1) self.save() self.resto.save()
def fans(self): return Fan.find_fans(ref_type=self.__class__.__name__, ref_pk=self.id)