from the book: requires is a validator or a list of validators. This is not used by the DAL, but it is used by SQLFORM
therefor fields like Field("manufacturer", requires=IS_IN_DB(db, db.test_manufacturer)), will probably get the default type (string). So you should define it with the apropriate type instead: Field("manufacturer", db.test_manufacturer, requires=IS_IN_DB(db, db.test_manufacturer)), regards, Alex On Tuesday, January 28, 2014 8:13:27 PM UTC+1, Ryan Matlock wrote: > > It appears that there are two ways to get a field to reference another > table, > Field("my_field", requires=IS_IN_DB(db, db.some_table)) > and > Field("my_field_2", db.some_table_2) > > The problem with both of these (and especially the first one), is that I > can't seem to get the format for my_field to grab the format of some_table > and my_field_2 can't grab the format from tables that some_table_2 uses in > its format. > > To be more concrete about it, I'm building an application that tracks > service work done on vehicles. I'd like to have a table of manufacturers, > then a table that references the manufacturers and associates them with > models, then configurations of those models, then particular vehicles that > associate a configuration and an owner with other data like the VIN. In > both formulations that I've tried, the admin interface becomes incredibly > confusing because I'm mostly having to remember what id is associated with > a particular entry. Here's a simplified version of my code so far: > > db.define_table("test_person", > Field("fname", > requires=IS_NOT_EMPTY()), > Field("lname", > requires=IS_NOT_EMPTY()), > format = "%(fname)s %(lname)s") > > db.define_table("test_manufacturer", > Field("name"), > format = "%(name)s") > > db.define_table("test_model", > Field("manufacturer", > requires=IS_IN_DB(db, db.test_manufacturer)), > Field("model_year"), > Field("model"), > format = "%(model_year)s %(manufacturer)s %(name)s") > > db.define_table("test_model_configuration", > Field("model", > requires=IS_IN_DB(db, db.test_model)), > Field("config", > label="Configuration"), > format = "%(model)s %(config)s") > > db.define_table("test_vehicle", > Field("vehicle_owner", > requires=IS_IN_DB(db, db.test_person)), > Field("model_config", > requires=IS_IN_DB(db, db.test_model_configuration), > label="model"), > Field("vin", > label="VIN"), > format = "%(vehicle_owner)s's %(model)s") > > db.define_table("test_model_2", > Field("manufacturer", > db.test_manufacturer), > Field("model_year"), > Field("model"), > format = "%(model_year)s %(manufacturer)s %(model)s") > > db.define_table("test_model_configuration_2", > Field("model", > db.test_model_2), > Field("config", > label="Configuration"), > format = "%(model)s %(config)s") > > db.define_table("test_vehicle_2", > Field("vehicle_owner", > db.test_person), > Field("model_config", > db.test_model_configuration_2, > label="model"), > Field("vin", > label="VIN"), > format = "%(vehicle_owner)s's %(model)s") > > I suppose I could get this to work if I had a "flatter" database. That > is, if I stuffed the manufacturer, model, and configuration into a single > table, the vehicle would only be "looking up" one table and could grab all > the information it needed. However, I can see this being a problem when I > want to start doing things with the vehicles (e.g. "John Doe's 1999 Honda > Accord LX"), which I don't want to be displayed as "82's 16 1" for which > I'd have to look up the id numbers to make any sense of it. > > If I need to ignore the admin interface entirely during this initial > testing phase, I'm still not sure what the most Pythonic/web2pythonic way > of getting all the information into my views is. My guess is that it would > be done in the controller by making a dictionary associating id numbers > with desired formats, but that seems like it would require a lot of > looping, which would bog everything down in a large-scale application. > > Basically, I'm completely stumped as to the "right" way to proceed. > -- 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/groups/opt_out.