You need to link Party to user not vice versa:

auth.settings.extra_fields['auth_user']= [
#    Field('partyID', 'reference Party'),
    Field('personMiddleName','string'),
    Field('gender','string'),    
  ]


db.define_table('Party', ## super-type for people and organizations
Field('user_id','reference auth_user'),
Field('partyTypeID','reference PartyType'), 
Field('displayName','string'))

db.Party.displayName.compute = lambda row: "%(first_name)s %(last_name)s" % 
db.auth_user[row.user_id]



On Monday, 6 May 2013 00:01:17 UTC-5, Alex Glaros wrote:
>
> In the controller below, how would I get auth_user.*first_name* and 
> auth_user.*last_name* (concatenated) into table Party, field *displayName*
> ?
>
> In other words, I'd like field displayName to end up with first_name and 
> last_name inside it.
>
> Party is the parent table and auth_user is the child table. Party is a 
> super-type that can be either a person or an organization.  
>
> I think experienced programmers would recommend against hitting the 
> database by joining Party table and auth_user table to create on-the-fly 
> calculated field  for displayName whenever a list of Party names is 
> displayed, right? I just have to be careful to update displayName whenever 
> first_name and last_name are subject to change.
>
> *Controller*
>
> def add_new_people():   
>     db.auth_user.partyID.readable = db.auth_user.partyID.writable = False ## 
> don't let user see field thinking they have to fill it in
>     db.Party.partyTypeID.readable = db.Party.partyTypeID.writable = False ## 
> don't let user see field thinking they have to fill it in
>     form=SQLFORM.factory(db.Party,db.auth_user)
>     db.Party.partyTypeID.default = 1 ## sets up db so it's a person, not 
> organization
>     if form.process().accepted:
>         partyID = db.Party.insert(**db.Party._filter_fields(form.vars))
>         form.vars.partyID=partyID
>         partyID = db.auth_user.insert(**db.auth_user._filter_fields(form.
> vars))    
>         response.flash='Thanks for filling the form'
>     return dict(form=form)
>
>
> *Model*
>
> auth.settings.extra_fields['auth_user']= [
>     Field('partyID', 'reference Party'),
>     Field('personMiddleName','string'),
>     Field('gender','string'),    
>   ]
>
>
> db.define_table('Party', ## super-type for people and organizations
> Field('partyTypeID','reference PartyType'), 
> Field('displayName','string'))
>
>
> thanks,
>
> Alex Glaros
>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to