Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow placeholders for other db model fields in render_table macro's action url_fors #145

Closed
caffeinatedMike opened this issue Jul 22, 2021 · 1 comment · Fixed by #146

Comments

@caffeinatedMike
Copy link
Contributor

caffeinatedMike commented Jul 22, 2021

Can we implement a way to allow for placeholders of all fields in the db model?

{{ render_table(
       portal_list,
       titles=headers,
       responsive=True,
       show_actions=True,
       edit_url=url_for('portals.edit_portal', portal_slug=':slug'),
       delete_url=url_for('portals.delete_portal', portal_slug=':slug')
 ) }}

In this case slug is a field in the Portal model, but it is not the primary key, nor is its data show in one of the table's columns. The whole purpose of using the slug is for a user-friendly url and portals in this case are the top object that all things relate back to.

  • /<portal_slug>/edit
  • /<portal_slug>/delete
  • /<portal_slug>/accounts
  • /<portal_slug>/accounts/new
  • /<portal_slug>/accounts/1/edit
  • /<portal_slug>/accounts/1/delete
  • /<portal_slug>/reports
  • And so on
class Portal(db.Model):
    __tablename__ = "portals"

    id = db.Column(db.Integer, primary_key=True)
    slug = db.Column(db.String(20), nullable=False, unique=True)
    display_name = db.Column(db.String(100), nullable=False, unique=True)


portals = Blueprint("portals", __name__)

@portals.route("/<portal_slug>/edit", methods=["GET", "POST"])
def edit_portal(portal_slug):
    # Do stuff here
    return render_template("portal.html", form=form)
@caffeinatedMike
Copy link
Contributor Author

As a temporary fix, I can set primary_key='slug' and change action_pk_placeholder=':slug' and it will work. But, this logic is misleading since slug is not really the model's primary key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant