When a user finishes adding a record in the WhatIfVote table, I want this 
function below to find only the parent WhatIf record to have its field 
numberOfTentativePartners have its contents replaced with the count of 
number of WhatIfVote records for that parent.

What is the syntax for selecting the parent only for this child, then 
adding up all its children and replacing the current value of 
numberOfTentativePartners with the new total?

Here's a walkthough of how it would work:

User adds a new WhatIfVote record. This is a child record.  

The function below then adds up all the children for the parent WhatIf and 
updates the parent field called numberOfTentativePartners with the total 
count of its children.

Here is the function that I'm trying to write:

def add_what_if_vote():
   form = SQLFORM(db.WhatIfVote)
   if form.process().accepted:
       response.flash = 'form accepted'
       query = (db.WhatIf.id == db.WhatIfVote.WhatIfID)
## PLEASE TYPE IN THE CORRECT SYNTAX FOR THE PSEUDO CODE IN THE LINE BELOW
      Where WhatIf.id == 
WhatIfVote.WhatIfID(db.WhatIf.insert(numberOfTentativePartners=select count 
of WhatIfVote where WhatIf.id == WhatIfVote.WhatIfID) 
   elif form.errors:
       response.flash = 'form has errors'
   else:
       response.flash = 'please fill out the form'
   return dict(form=form)   

%%%%%%%%%%%    Models    %%%%%%%%

## ----- Parent table -----------

db.define_table('WhatIf', ## Table - What-if process.This table enables 
What-If Analysis 
Field('shorWhatIfDescription', 'string',label='Description'), 
Field('numberOfTentativePartners', 'integer')) ## always derived by 
counting number of WhatIfVote children records whenever a new WhatIfVote 
child is added


## ---- Child table ----------
db.define_table('WhatIfVote', ##  Whenever a new record is added, the total 
children for the parent are totaled in the parent record in field 
numberOfTentativePartners 
Field('WhatIfID', 'reference WhatIf'),  
Field('whatIfVoteComments', '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