I want to select one of many parent records, and send selection parm, 
parent_id to sqlFactory to add child record.  I think I need a virutual 
filed for this, correct?

Goal is to add a new address, to an already-existing address for parent 
table db.Party.  db.Address contains addresses only, and 
db.PartyAddressIntersection is where the one-to-many addresses are linked 
to db.Party.

Can anyone please write the code for creating a virtual field in parent 
table db.Party, that sends user to Factory with correct parms for parent 
record?

There is an already-existing controller for adding both a totally new 
parent, and child below (add_new_person).  What is needed, besides the 
parms, is a controller that that looks like the already-existing one below, 
but does not add a new parent.  It gets the parent_id (PartyID) sent to it 
from the virtual field.

To summarize:


   1. User scrolls through sqlForm searching through table db.Party. At the 
   end of each record, is a virtual field that is a link that user can click 
   on labeled "click here to add another address to this party".
   2. The link sends user to Factory, and also sends the record_id for the 
   row that user selected.  
   3. Factory reads the record_id sent to it from the link and creates a 
   new address for the correct parent, db.Party. To do this, it adds a new 
   record to two tables, db.PartyAddressIntersection and db.Address
   

Here are the models

db.define_table('Address', ## no reference to Party in this table.  Just 
addressses.  Party is referenced in intersection table below.
Field('addressLine_1','string'), 
Field('addressLine_2','string'), 
Field('addressLine_3','string'), 
Field('subDistrictOrTwonshipOrCantonOrWard','string'), 
Field('district','string'),
Field('city','string'),  
Field('countyOrParish','string'), 
Field('stateOrProvinceOrCommonwealth','string'), 
Field('zipOrPostalCode','string'), 
Field('countryCode','string'))
## 
------------------------------------------------------------------------------------------
db.define_table('PartyAddressIntersection',
Field('partyID','reference Party'), 
Field('addressID','reference Address'), 
Field('addressTypeID','reference AddressType',comment='Choose address type, 
or email us to suggest a new category'))

Here is the controller that needs to be modified so that it accepts 
parent_record_id from link and doesn't add record to parent tables 
(ObjectSuperType, auth_user, Party). It only has to add records to 
db.Address and db.PartyAddressIntersection.

def add_new_person():
    db.ObjectSuperType.objectTypeID.readable = 
db.ObjectSuperType.objectTypeID.writable = False ## don't let user see 
field thinking they have to fill it in 
    db.Party.objectID.readable = db.Party.objectID.writable = False ## 
don't let user see field thinking they have to fill it in
    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
    db.PartyAddressIntersection.addressID.readable = 
db.PartyAddressIntersection.addressID.writable = False ## don't let user 
see field   
    db.Address.id.readable = db.Address.id.writable = False ## don't let 
user see field  
    db.Party.partyTypeID.default = 1 ## sets up db so it's a person, not 
organization
    db.ObjectSuperType.objectTypeID.default = 1  ## sets up db so object 
type is designated as a party (not a component)         
    
form=SQLFORM.factory(db.ObjectSuperType,db.Party,db.auth_user,db.PartyAddressIntersection,db.Address)
    if form.process().accepted:
        objectID = 
db.ObjectSuperType.insert(**db.ObjectSuperType._filter_fields(form.vars))
        form.vars.objectID=objectID
        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))
        addressID = 
db.Address.insert(**db.Address._filter_fields(form.vars))
        form.vars.addressID=addressID        
        partyID = 
db.PartyAddressIntersection.insert(**db.PartyAddressIntersection._filter_fields(form.vars))
 
          
        response.flash='Thanks for filling the form'
    return dict(form=form)

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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to