Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>unique=True</code> is enforced by the database, not by the form validation process. If you attempt to insert a value that is already in the database, the database should return an error, which should trigger an error in your web2py application (but you won't get a nice error message displaying on the form). If you want the form validation to check for duplicates, you should use the IS_NOT_IN_DB validator:</p> <pre><code>Field('main_watershed', 'string', requires=IS_NOT_IN_DB(db, 'watershed.main_watershed')) </code></pre> <p>Also, rather than storing duplicates of the "project_name" field in the watershed table, you might consider making that a reference field:</p> <pre><code>db.define_table('project', Field('project_name', 'string',unique =True), auth.signature, format='%(project_name)s') db.define_table('watershed', Field('project', 'reference project'), Field('main_watershed', 'string', requires=IS_NOT_IN_DB(db, 'watershed.main_watershed')), auth.signature) </code></pre> <p>You should also use the URL() function in your redirect: <code>redirect(URL('default', 'add_main'))</code></p> <p>Finally, to make it easier to add watersheds for the recently added project, you might consider passing the id of the project to the add_main function and have it set that as the default value for the project:</p> <pre><code>def add_project(): form = SQLFORM(db.project).process() if form.accepted: redirect(URL('default', 'add_main', args=form.vars.id)) return dict(form = form) def add_main(): project_id = request.args(0, cast=int, default=None) db.watershed.project.default = project_id form = SQLFORM(db.watershed).process() if form.accepted: redirect(URL('default', 'add_main', args=project_id) LIST = db(db.watershed).select() return dict(form = form, LIST = LIST) </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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