def handle(self, text): to_unfollow = find_objects( text, followable_models()) for obj in to_unfollow: try: obj.followers.get(**self.msg.persistance_dict).delete() except obj.DoesNotExist: pass if to_unfollow: self.respond( "You are no longer following: %s." % (", ".join(map(unicode, to_unfollow)))) else: self.respond("Sorry, I couldn't understand what you want to stop following.")
def handle(self, text): # fetch a list of objects (any model) that # match the query via the __search__ api to_follow = find_objects( text, followable_models()) # link this reporter to the "followers" reverse foreign key # of each object (whatever model it is -- they're all named # "followers"). this works with unidentified connections too, # even if that doesn't make much sense most of the time for obj in to_follow: obj.followers.get_or_create( **self.msg.persistance_dict) if to_follow: self.respond( "You are now following: %s." % (", ".join(map(unicode, to_follow)))) # if we didn't understand _any_ of what the # caller asked us to follow, return an error else: self.respond("Sorry, I couldn't understand what you want to follow.")