I'm having a small bit of trouble understanding how SQLFORMS work.

I have created a custom profile for auth and I have a separate table
which includes items for each user.  I don't want each user to have
multiple records in this table but instead I want them to be able to
create a new one if it doesn't exist and change/modify only that one
if they want to without inserting new records.

Here is what I have so far which I got from my manual but it isn't
behaving the way I thought it would.  Of course I am still learning
this so any help would be appreciated.  I want them to be able to go
to something like localhost.com/something/default/services and only be
able to update their record.

@auth.requires_login()
def services():
    if len(request.args):
        records = db(db.services.user==auth.user.id).select()
    if len(request.args) and len(records):
        form = SQLFORM(db.services, records[1], deletable=False)
        form.vars.user = auth.user.id
    else:
        form = SQLFORM(db.services)
        form.vars.user = auth.user.id
    if form.accepts(request.vars, session):
        response.flash = 'form accepted'
    elif form.errors:
        response.flash = 'form has errors'
    return dict(form=form)

Reply via email to