First of all let me congratulate for the clear format of your
question.
This line:

    db.report.from_id.requires = IS_IN_DB(db, db.version.id, '%(name)s
%(version)s')    # Again, I want a set, not a list.

does not display the cartesian product of name and version but only a
list of name, version for every record in db.version. Some entries are
repeated because name+version is not a unique key of db.version.

As I see it this is a logical problem.

The table version contains a link between an application version and a
component version. It basically implements a many-2-many relation but
without a source table. The missing source table is the one you want
to reference in from_id. The source table is a table that contains
lists of application name,version and all entries are unique.

My suggestion is change the model:

db.define_table('application',
    Field('name'),
    Field('version'),
    format='%(name)s %(version)s')
#make sure name+version is unique for applications
db.application.version.requires=IS_NOT_IN_DB(db
(db.application.name==request.vars.name),db.application.version)

db.define_table('component',
    Field('name'),
    Field('version'(,
    Field('label'),
    format='%(name)s %(version)s')
)
#make sure name+version is unique + components
db.component.version.requires=IS_NOT_IN_DB(db
(db.component.name==request.vars.name),db.component.version)

db.define_table('usage',
    Field('application_id', db.application),
    Field('component_id', db.component))

db.define_table('report',
    Field('from_id', db.application),
    Field('to_id', db.application))

If you use 1.74.4 and the format attribute you do not need to set any
of the IS_IN_DB validators. I think this will be what you want. The
tables "applicaiton" and "usage" replace your table "version".

On Dec 27, 9:18 pm, Christopher Helck <christopher.he...@gmail.com>
wrote:
> I apologize if this is more of a DB question than a web2py question, but I'm
> having trouble with populating a drop down menu in the admin interface. I
> have a table (called 'version')  with two keys ('name'  and 'version') and a
> third column 'component_id'. This table records which versions of an
> application use which software component: Example data:
>
>    Name, Version, Component
>    credit, 1.0.0      commons_all_1.2
>    credit, 1.0.1,     commons_all_1.3
>    credit, 1.0.0      commons_pools_6.3
>    credit, 1.0.1,     commons_pools_6.5
>
> Interpretaion: The credit application 1.0.0 uses commons_all_1.2 and
> commons_pools_6.3
>                     The credit application 1.0.1 uses commons_all_1.3 and
> commons_pools_6.5
>
> The problem occurs when I reference the version table from another table.
> The drop down list contains:
>       credit 1.0.0
>       credit 1.0.0
>       credit 1.0.1
>       credit 1.0.1
>
> I want the drop down menu to display the set {name, version}, instead of the
> cartisian product of the two keys. Here's my db.py:
>
> db.define_table('component',
>     Field('component_name'),
>     Field('component_version'),
>     Field('label'))
>
> db.define_table('version',
>     Field('name'),
>     Field('version'),
>     Field('component_id', db.component))
>
> db.define_table('report',
>     Field('from_id', db.version),            # Drop down menu has cartisian
> product of version.name X version.version
>     Field('to_id', db.version))
>
> db.version.component_id.requires = IS_IN_DB(db, db.component.id,
> '%(component_name)s %(component_version)s')
> db.report.from_id.requires = IS_IN_DB(db, db.version.id, '%(name)s
> %(version)s')    # Again, I want a set, not a list.
> db.report.to_id.requires = IS_IN_DB(db, db.version.id, '%(name)s
> %(version)s')
>
> Thanks,
> C. helck

--

You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to