By setting deletable attribute to True, user will have an option to delete existing record during record update process.
Model db.py
Specify category table using define_table.
| db.define_table('category',
Field('is_enabled', 'boolean', default=True, label=T('Enabled')),
Field('name', 'string', length=256, label=T('Name')),
Field('description', 'text', readable=True, writable=True, label=T('Description')),
format='%(name)s'
) |
Controller default.py
Using request.args update specific record using SQLFORM(). By specifying deletable to True a form option will be given to a user.
| def edit_category():
if not len(request.args):
response.flash = 'Something happended that shouln\'t happened, lets start from the start'
redirect(URL('home','references'))
else:
record_id = request.args(0)
form = SQLFORM(db.category,record_, showid = False,deletable=True, fields = ['is_enabled','name'])
return dict(form=form) |
View default/edit_category.html
Show update form by entering {{=form}}
| {{extend 'layout.html'}}
{{=form}} |
Result
loading...