you're right - I probably could have just iterated through each field and 
set the default before calling .factory() with readonly - I didn't try 
that.  The method I came up with is very simple so I'm ok with it now.

for the email/username, .factory() tries to validate the fields even if 
they don't change and it includes all existing values, including the 
current row, so the validation fails.  I avoid that by specifying the list 
of values for the 'not_in_db' validator to exclude the current row.


On Thursday, April 21, 2016 at 2:05:30 PM UTC-4, Richard wrote:
>
> I am not sure, but .factory() should accept readonly=True for read form...
>
> Are you sure you have not any fields with the same name in both tables?
>
> On Thu, Apr 21, 2016 at 2:00 PM, Richard Vézina <ml.richa...@gmail.com 
> <javascript:>> wrote:
>
>> Michael,
>>
>> About displaying value use default = when you create input field it 
>> should be all what you need...
>>
>> About the other problem I don't get it... You should be able to update a 
>> record email/username as long as the new value is unique...
>>
>> Richard
>>
>> On Wed, Apr 20, 2016 at 11:43 PM, Michael Beller <mjbe...@gmail.com 
>> <javascript:>> wrote:
>>
>>> Thanks Richard, I should have provided more details.
>>>
>>> When I tried to create a form using SQLFORM.factory for two tables 
>>> (including auth_user), I would get an error that the auth_user email and 
>>> username existed even if I wasn't updating those fields.  It appears that 
>>> the validator to assure those fields are unique does not exclude the 
>>> current values.  I was able to fix this by adding these before calling 
>>> SQLFORM.factory:
>>>
>>>     emails = db(db.auth_user.email != user.email)
>>>     db.auth_user.email.requires = IS_NOT_IN_DB(emails, 'auth_user.email'
>>> )
>>>     usernames = db(db.auth_user.username != user.username)
>>>     db.auth_user.username.requires = IS_NOT_IN_DB(usernames, 
>>> 'auth_user.username')
>>>
>>> My entire function to create an edit form for two tables:
>>>
>>> def edit():
>>>     
>>>     investor = db.investor(request.args(0)) or redirect(URL('index'))
>>>     user = db.auth_user(investor.auth_user)
>>>
>>>     emails = db(db.auth_user.email != user.email)
>>>     db.auth_user.email.requires = IS_NOT_IN_DB(emails, 'auth_user.email'
>>> )
>>>     usernames = db(db.auth_user.username != user.username)
>>>     db.auth_user.username.requires = IS_NOT_IN_DB(usernames, 
>>> 'auth_user.username')
>>>
>>>     db.auth_user.password.writable = False
>>>     db.investor.auth_user.readable = False
>>>     db.investor.auth_user.writable = False
>>>
>>>     form = SQLFORM.factory(db.auth_user, db.investor)
>>>
>>>     for f in db.investor.fields:
>>>         form.vars[f] = investor[f]
>>>     for f in db.auth_user.fields:
>>>         form.vars[f] = user[f]
>>>
>>>     if form.validate():
>>>         investor.update_record(**db.investor._filter_fields(form.vars))
>>>         user.update_record(**db.auth_user._filter_fields(form.vars))
>>>         session.flash = '%s updated!' % table._singular
>>>         redirect(URL(request.controller, 'list'))
>>>     elif form.errors:
>>>         response.flash = 'Please correct the errors'
>>>
>>>     response.view = 'template/edit.html'
>>>     return dict(item_name=table._singular, form=form)
>>>
>>> Now I'm working on a readonly form but the readonly option for 
>>> SQLFORM.factory doesn't display the values from form.vars so I may just 
>>> generate the form manually.
>>>
>>> On Wednesday, April 20, 2016 at 3:58:37 PM UTC-4, Richard wrote:
>>>>
>>>> Hello Michael,
>>>>
>>>> I am not sure to understand what you are trying to acheive exactly and 
>>>> what is causing issue...
>>>>
>>>> On Wed, Apr 20, 2016 at 2:18 PM, Michael Beller <mjbe...@gmail.com> 
>>>> wrote:
>>>>
>>>>>
>>>>> The approach in the book for one form for multiple tables works well 
>>>>> for create forms:
>>>>>
>>>>> http://web2py.com/books/default/chapter/29/07/forms-and-validators#One-form-for-multiple-tables
>>>>>
>>>>> I have not found a good method for view or update forms.
>>>>>
>>>>> I have a model:
>>>>>
>>>>> db.define_table('buyer', Field('auth_user', 'reference auth_user', ...)
>>>>> db.define_table('seller', Field('auth_user', 'reference auth_user', 
>>>>> ...)
>>>>>
>>>>> Each buyer is associated with one user and each seller is associated 
>>>>> with one user.  I'd like to have one form to view and edit each buyer and 
>>>>> seller that includes their user profile.
>>>>>
>>>>> I've tried variations of
>>>>>
>>>>> https://groups.google.com/forum/#!searchin/web2py/sqlform.factory$20edit/web2py/fvzIHyN7eP4/ZixpDiTl1GUJ
>>>>> and
>>>>> https://groups.google.com/forum/#!topic/web2py/hpH7a3Qz3Wg
>>>>>
>>>>> Has anybody found a good solution?
>>>>>
>>>>> -- 
>>>>> Resources:
>>>>> - http://web2py.com
>>>>> - http://web2py.com/book (Documentation)
>>>>> - http://github.com/web2py/web2py (Source code)
>>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>>> --- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "web2py-users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to web2py+un...@googlegroups.com.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> -- 
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to web2py+un...@googlegroups.com <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to