That's not valid Python code, but you can do this: db.payment_allocations.insert(**{'payment_ref': payment.id, ref_field: record.id, 'amount_allocated': allocation})
Anthony On Wednesday, June 7, 2017 at 10:42:28 PM UTC-4, Peter wrote: > > > Good Morning. > > I'm hoping there is a way to solve this... > > This works fine for me... > > db.payment_allocations.insert(payment_ref=payment.id, > task_ref=record.id, > amount_allocated=allocation) > > but I want to add a little abstraction like this... > > ref_field = '%s_ref' % table_name # where resulting field name > will be either 'task_ref' or 'invoice_ref' (both fields are valid in the > insert table). > db.payment_allocations.insert(payment_ref=payment.id, > ref_field=record.id, > amount_allocated=allocation) > > which currently gives an Attribute Error (taking ref_field literally and > not substituting the variable's assigned value) > > Is this possible to achieve what I want? > Any pointers would be appreciated. > > Thanks > Peter > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.