Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete List Item From Database
    primarykey
    data
    text
    <p>This is probably a simple question, I have a form that you put in a comment it redirects to another page upon submit and displays all comments in a list. I am wondering how i can add an erase button to each list item to remove that particular comment. </p> <p>Thank you in advance, </p> <pre><code>db.define_table('discussion', Field('comment', 'text')) def comment(): form = SQLFORM(db.discussion, _class='test1') if form.process().accepted: redirect(URL('comment_results')) return dict(form=form) def comment_results(): items = db(db.discussion.id==db.discussion.id).select() ???? erase = db(db.discussion.id==).delete() ???? ### trying to create an erase button to delete the currently displayed comment ### return dict(items=items, erase=erase) view: &lt;html&gt; &lt;head&gt; &lt;link rel="stylesheet" href="{{=URL('static','css/test.css')}}"&gt; &lt;/head&gt; &lt;body&gt; {{for item in items:}} &lt;li&gt;{{=item.id}} Comment = {{=item.comment}}&lt;button id="{{=erase}}"&gt;erase&lt;/button&gt;&lt;/li&gt; {{pass}} &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>* Answer *</strong> View:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;link rel="stylesheet" href="{{=URL('static','css/test.css')}}"&gt; &lt;/head&gt; &lt;body&gt; {{for item in items:}} {{=item.comment}}&lt;a href="{{=URL('delete', args=item.id)}}"&gt; Delete&lt;/a&gt; {{pass}} &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>* I just passed the args to the delete method in the controller *</strong> Controller:</p> <pre><code>def delete(): query = db(db.discussion.id==request.args(0)).select().first() ## grabbing comment to be deleted from comment_results remove = db(db.discussion.id==query).delete() if remove: redirect(URL('comment_results')) return dict(remove=remove) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload