def add_friend(self, other): if self != other: if other not in self.friends: self.friends.append(other) if self not in other.friends: other.friends.append(self) db_session.flush()
def remove_friend(self, other): if other.best_friend == self: other.best_friend = None # Needed to avoid sqlalchemy.exc.CircularDependencyError db_session.flush() if self.best_friend == other: self.best_friend = None if self not in other.friends: raise Exception self.friends.remove(other) other.friends.remove(self) db_session.flush()
def make_best_friend(self, other): if other not in self.friends: raise Exception self.best_friend = other db_session.flush()