I had tried that exact if statement however I did not add a second {{pass}}
!!! thank you for having me take a look at that again, I knew it was
something small I was overlooking.
On Tuesday, December 3, 2013 9:59:03 AM UTC-8, EW wrote:
>
> The logic you have currently loops through and creates rows for all
> tcinputs for each timecard and that is why they are all the same.
>
> I can think of 2 solutions:
> 1) Keep your queries the same but add an if statement to determine which
> of the tcinputs apply:
>
> {{for timecard_entry in tcinputs:}}
>
>
>
> {{if timecard_entry.timecard==timecard.id:}}
>
>
>
>
> <tr><td>{{=timecard_entry.company.name}}</td>....etc
>
>
>
>
> {{pass}}
>
>
>
> {{pass}}
>
> 2) Make one query in the controller with something like tcrows =
> db(db.timecard_entry.timecard==db.timecard.id
> ).select(orderby=~db.timecard.tc_date)
>
> But then the code in the view is a little more complicated--you would need
> to check for when you reach a "new" timecard so that you know when to
> end/create your tables. Also note that if you used this query, it contains
> fields from both tables so to access the variables you need to specify the
> tablename e.g.
> {{for t in tcrows:}}
> <tr><td><strong>{{=A(t.timecard.employee.fname, etc, etc
> <tr><td>{{=t.timecard_entry.company.name}}, etc, etc
> {{pass}}
>
>
> On Monday, December 2, 2013 9:20:38 PM UTC-8, Jesse Ferguson wrote:
>
>> I have two tables set up and i want to show the TimeCard with all the
>> entries for said time card however im unsure of how to create such a view...
>>
>> CONTOLLER:
>>
>> def timecard_index():
>> tcrows =db(db.timecard).select(orderby=~db.timecard.tc_date)
>> tcinputs
>> =db(db.timecard_entry).select(orderby=db.timecard_entry.timecard)
>> return locals()
>>
>> MODEL:
>>
>> db.define_table('timecard',
>> Field('tc_date','date'),
>> Field('employee', 'reference
>> employee',requires=IS_IN_DB(db,'employee.id','%(fname)s %(lname)s')),
>> Field('myid', unique=True, compute=lambda r: str(r.tc_date)
>> + str(r.employee))
>> )
>>
>> db.define_table('timecard_entry',
>> Field('timecard', 'reference timecard', readable=False,
>> writable=False,),
>> Field('company', 'reference company', label='Company'),
>> Field('tc_start', 'time',
>> requires=[IS_TIME(),IS_NOT_EMPTY()], label='Start'),
>> Field('tc_stop', 'time',
>> requires=[IS_TIME(),IS_NOT_EMPTY()], label='Stop'),
>> Field('st' , 'double', label='ST', default=0.0),
>> Field('ot' , 'double', label='OT', default=0.0),
>> Field('dt' , 'double', label='DT', default=0.0),
>> Field('tc_classification' ,'string', label='Classification'),
>> auth.signature)
>>
>> VIEW:
>>
>> {{for timecard in tcrows:}}
>> <div class="well">
>> <table>
>> <tr><td><strong>{{=A(timecard.employee.fname +'
>> '+timecard.employee.lname,_href=URL('view_timecard',args=timecard.id))}}
>> {{=timecard.tc_date.strftime("%m.%d.%Y")}}</strong></td></tr>
>> {{for timecard_entry in tcinputs:}}
>>
>> <tr><td>{{=timecard_entry.company.name}}</td><td>{{=timecard_entry.tc_start}}</td><td>{{=timecard_entry.tc_stop}}</td><td>{{=timecard_entry.st}}</td><td>{{=timecard_entry.ot}}</td><td>{{=timecard_entry.dt}}</td><td>{{=timecard_entry.tc_classification}}</td></tr>
>> {{pass}}
>> </table>
>> </div>
>> {{pass}}
>>
>> This results in the same entries being put into each timecard (not the
>> correct ones), I know I'm missing something in the logic but I'm too green
>> of a programmer to see it... Im also not sure if im making the correct
>> query for tcinputs...
>>
>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.