def METHOD_NAME(client_id):
    client = Client.get(client_id)
    if not client:
        flash("no such app", "warning")
        return redirect(url_for("developer.index"))
    if client.user_id != current_user.id:
        flash("you cannot see this app", "warning")
        return redirect(url_for("developer.index"))
    if request.method == "POST":
        referral_id = request.form.get("referral-id")
        if not referral_id:
            flash("A referral must be selected", "error")
            return redirect(request.url)
        referral = Referral.get(referral_id)
        if not referral or referral.user_id != current_user.id:
            flash("something went wrong, refresh the page", "error")
            return redirect(request.url)
        client.referral_id = referral.id
        Session.commit()
        flash(f"Referral {referral.name} is now attached to {client.name}", "success")
    return render_template("developer/client_details/referral.html", client=client)