Grouping information with its client

11 views
Skip to first unread message

mostwanted

unread,
Apr 9, 2022, 3:13:03 PMApr 9
to web2py-users
Guys i need help here, I have an insurance database that has 3 tables of information that relates to the client (account holder), what i want to do is to be able to group each piece of information according to its owner (account holder) in an html table in the view and not have it mixed up. Have client A details in row 1, client A children details in row 2 and client A parents information in the following row. From there client B and his information in the subsequent rows then client C & so on. How can i achieve this??

MODELS
db.define_table('client',
                Field('gender', requires=IS_IN_SET(['Mr', 'Mrs', 'Miss'], zero='---Select Gender---')),
                Field('last_name', requires=IS_NOT_EMPTY()),
                Field('first_name', requires=IS_NOT_EMPTY()),
                Field('id_number', requires = IS_MATCH('^\d{9}?$', error_message='An ID Number should have exactly 9 digits')))

db.define_table('children',
                Field('client', 'reference client', writable=False),
                Field('gender', requires=IS_IN_SET(['Male', 'Female', 'None'], zero='---Select Gender---')),
                Field('childs_full_names', requires=IS_NOT_EMPTY()),
                Field('dob', 'date', requires=IS_NOT_EMPTY()),
               )

db.define_table('parents_and_in_laws',
                Field('client', 'reference client', writable=False),
                Field('gender', requires=IS_IN_SET(['Mr', 'Mrs', 'Miss', 'None'], zero='---Select Gender---')),
                Field('full_name', requires=IS_NOT_EMPTY()),
                Field('id_number', requires = IS_MATCH('^\d{9}?$', error_message='An ID Number should have exactly 9 digits')),
                Field('relationship', requires=IS_NOT_EMPTY()))

Controller:
def client_policy_packages():
    nuclear=db(db.newclear_family.).select(db.newclear_family.ALL)
    children=db(db.children).select(db.children.ALL)
    parent=db(db.parents_and_in_laws).select(db.parents_and_in_laws.ALL)
    extended=db(db.extended_family).select(db.extended_family.ALL)
    return locals()

View:
------------------------

mostwanted

unread,
Apr 10, 2022, 5:26:55 AMApr 10
to web2py-users
I was able to figure this out & this is how i did it:

<table>
    <th>Owner</th>
    <th>Gender</th>
    <th>ID Number</th>
    <th>Relationship</th>
    <th>Policy</th>
    <th>Category 1</th>
    <th>Category 1 Premium</th>
    <th>Category 1 Benefits</th>
    <th>Category 2</th>
    <th>Category 2 Premium</th>
    <th>Category 2 Benefits</th>
   
            {{for nu in nuclear:}}

    <tr>
        <td>{{=client_name(nu.client)}}</td>
        <td>{{=nu.client.gender}}</td>
        <td>{{=nu.client.id_number}}</td>
        <td>{{=nu.client.relationship}}</td>
        <td>{{=nu.policy_1}}</td>
       
        <td>{{=nu.member_only.package_name}}</td>
        <td>{{=nu.member_only.montly_subscription}}</td>
        <td>{{=nu.member_only.take_away_package}}</td>
   
        <td>{{=nu.member_and_newclear_family.package_name}}</td>
        <td>{{=nu.member_and_newclear_family.montly_subscription}}</td>
        <td>{{=nu.member_and_newclear_family.take_away_package}}</td>
        <td></td>
        </tr>

    <tr>
        <td>{{=client_name(nu.client)}}</td>
        <td>{{=nu.spouse_full_name}}</td>
        <td>{{=nu.relationship}}</td>
        <td>{{=nu.id_number}}</td>
    </tr>
    <tr>
            {{for ch in children:}}
{{if ch.client.id==nu.client.id:}}
        <td>{{=client_name(ch.client)}}</td>
        <td>{{=ch.childs_full_names}}</td>
        <td>{{=ch.relationship}}</td>
        <td>{{=ch.policyCover.package_name}}</td>
        <td>{{=ch.policy_benefit}}</td>
        {{pass}}
    </tr>
    {{pass}}
    <tr>
            {{for pr in parent:}}
        {{if pr.client.id==nu.client.id:}}
        <td>{{=client_name(pr.client)}}</td>
        <td>{{=pr.full_name}}</td>
        <td>{{=pr.relationship}}</td>
        <td>{{=pr.policy_1}}</td>
        <td>{{=pr.parent_policy.package_name}}</td>
        <td></td><td></td><td></td><td></td><td>{{=pr.parent_policy.montly_subscription}}</td>
        {{pass}}
    </tr>
    {{pass}}
    <tr>
            {{for ex in extended:}}
        {{if ex.client.id==nu.client.id:}}
        <td>{{=client_name(ex.client)}}</td>
        <td>{{=ex.full_names}}</td>
        <td>{{=ex.relationship}}</td>
        <td>{{=ex.policy_1}}</td>
        <td>{{=ex.extended_family.package_name}}</td>
        <td></td><td></td><td></td><td></td><td>{{=ex.extended_family.montly_subscription}}</td>
        {{pass}}
    </tr>
    {{pass}}
    {{pass}}
</table>

currently so far so good
Reply all
Reply to author
Forward
0 new messages