def unfollow(idol_id): idol = User.get_or_none(User.id == idol_id) relationship = FanIdol.get(FanIdol.idol == idol.id, FanIdol.fan == current_user.id) relationship.delete_instance() flash(f"Unfollowed {idol.name}") return redirect(url_for('users.show', id=idol.id))
def unfollow(idol_id): idol = User.get_or_none(User.id == idol_id) relationship = FanIdol.get(FanIdol.idol == idol.id, FanIdol.fan == current_user.id) #this will help me wrap and get FanIdol (where, select your FanIdol.idol (from db) is equal to idol.id (from this funtion), select your FanIdol.fan (from db) comapre with current_user.id (from function)) #this line 2 conditions need to be wrap it relationship.delete_instance( ) # (using previous variable) delete using delete_instance() then save flash(f"You are now unfollow {idol.name}") return redirect(url_for('users.show', username=idol.username))
def user_unfollow(id): user = User.get_by_id(id) idol = FanIdol.get(FanIdol.idol == user.id, FanIdol.fan == current_user.id) if current_user.unfollow(user): if idol.is_approved: flash ("Successfully unfollowed","success") return redirect(url_for("users.show",username = user.username)) else : flash ("Request cancelled","success") return redirect(url_for("users.show",username = user.username)) else : flash ("Something went wrong. Try again.", "danger") return redirect(url_for("users.show",username = user.username))