I'm currently attempting to write a web2py application to keep track of
servicing at the shop where I work as a mechanic. This is my first
experience at web2py, so please excuse me if the answer to this is obvious.
The problem that I have right now is how objects that are built up from
nested tables are displayed. That's probably a poor way of describing it,
so I'll demonstrate. Here's a simplified version of what I'm trying to do:
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 %(name)s")
db.define_table("test_vehicle",
Field("vehicle_owner",
requires=IS_IN_DB(db, db.test_person)),
Field("model",
requires=IS_IN_DB(db, db.test_model)),
Field("vin",
label="VIN"),
format = "%(vehicle_owner)s's %(model)s")
So if I go to the admin interface and try to add a new record for
test_vehicle, I get a drop down list of id integers instead of names.
There was a suggestion I found somewhere on stackexchange that looks like
the following:
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_vehicle_2",
Field("vehicle_owner",
db.test_person),
Field("model",
db.test_model_2),
Field("vin",
label="VIN"),
format = "%(vehicle_owner)s's %(model)s")
That solution nearly works. Now when I made a new test_model_2 instance, I
can see if I'm working with a Honda or a Toyota instead of a 1 or a 2.
However, when I try to make a new test_vehicle_2 record, I can select from
things like "2011 1 Accord" instead of "2011 Honda Accord".
I suppose I could deal with the admin interface being pretty much useless
for adding new records, but I'm not sure what the most
Pythonic/web2pythonic way of making controllers/views to enter new data
would be. I can also see how making my database "flatter" might help (i.e.
don't separate manufacturer and model into different tables), but I'm sure
I'll run into problems trying to make everything reference something only
one level above itself.
--
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.