Ok. I have most of the logic, application going. I am not using grids all the times. This is what I struggle the most with py4web.
There is no real way to pass on a value to populate another table and be able to query both based on the relationship of these two.
I have a customer table and a locations table, for the sake of simplicity, I will just add a few fields from it:
db.define_table ('customer',
Field ('company'),
Field('contactname'))
db.define_table('locations',
Field('customer', 'reference customer')
Field('address'))
If I have a form that gives me the customer information, that is company and contactname and I have a button that would be to add a location for that customer, how in the world do I pass that customer id to the other locations table?
The code below, used to work but not anymore. And I have not changed anything other than upgrade py4web:
@authenticated('newlocation/<id:int>','customer_location.html')
def customerlocation(id=None):
if id is None:
redirect(URL('custindex'))
customer = db.customer[id]
db.locations.customer.default = customer
form = Form(db.locations, csrf_session=session, formstyle=FormStyleBootstrap4)
if form.accepted:
redirect(URL('order', form.vars['id']))
return dict(form=form)
I just cant wrap my head around as to how can anyone work with relational databases if there are relations in tables without any relation at all? or am I missing something?
By accomplishing what I want above, as a simple example, I should be able to eventually create queries such as list of customers and their locations etc etc etc.
The grid is able to create the relationship so why cant I?
I have browsed over and over the documentation. cant find the answer. and like I said, it used to work before, not it doesnt.
Thanks