Hi, The company I work for places environmental measuring devices at different locations. I've designed a simple database to keep track of where we have devices. One thing that's important to us is how long a device has been on site.
It's probably easiest to understand if I just paste some code. Here's a sample: Controller: def viewbystatus(): places = db(db.plads.status == request.args(0)).select() or redirect(URL('index')) statusstring = db.status(request.args(0)).status return dict(places=places, status=statusstring) View: {{extend 'layout.html'}} {{def Linkify(element, id, method): return A(element, _href=URL(method, args=(id)))}} <h1>{{=status}}</h1> <h3>{{=str(len(places)) + ' sites'}}</h3> <table> <thead><tr> <td>Name</td><td>Address</td><td>Zipcode</td><td>City</td><td>State</ td><td>Sitefinder</td><td>NumBoxes</td><td>DatePlaced</td> </tr></thead> {{for row in places:}} {{elements = [Linkify(element, row.id, 'show') for element in [row.name, row.address, row.zipcode, row.city, row.state.state, row.sitefinder.wardname, row.numboxes, row.dateplaced]]}} {{=TR(elements)}} {{pass}} </table><br> <br> [{{=A('Return to index', _href=URL('index'))}}] Essentially, I would like to replace the DatePlaced column in the view with something like DaysOnSite. It's a simple matter of datetime.date.today() - row.dateplaced. I could easily calculate this in the for loop in the view. Is that correct practice? Should I be calculating it in the controller? Should I add a column in the database and recalculate/update on each access? For some context, there are a couple of different views where it would be useful to see the number of days on site. So, what's the correct thing to do here?