On Dec 28, 10:23 pm, Christopher Helck <[email protected]>
wrote:
> Thanks for the response. I believe I understand your suggestion. DBs are not
> one of my areas of strength, and so I'm struggling with issues that may be
> simple. So, I have a few  follow up questions:
>
> Question 1
> In:
>
> db.define_table('application',
>    Field('name'),
>    Field('version'),
>    format='%(name)s %(version)s')
>
> What is the purpose of the 'format' argument? Does it some how control how a
> pull down menu is formated? or how each row is printed in a report? or is it
> some proper DB thing?

format is used to set field.requires=IS_IN_DB
(db,reference_field,format) automatically for all fields that
reference this table.

>
> Question 2
> How should I understand the statement:
>
> db.application.version.
>
>
>
> > requires=IS_NOT_IN_DB(db
> > (db.application.name==request.vars.name),db.application.version)
>
> First, what is it suppose to mean? Something like "allow the update if and
> only if rows who's name matches the request's name do not already have the
> given version"?

It is a trunk to make sure that the combination name+version is
unique. It requirest that the version is in not the the set db(...)
where db(...) is the set of records with the same name as the one
submitted.

> Second, I can't make sense of the second argument. Doesn't it just evaluate
> to a boolean, and get passed into IS_NOT_IN_DB()? Does the code get reparsed
> for every form and row? How does it work? I assume the intent is that the
> second argument is some sort of function that get evaluated against each
> row.

IS_NOT_IN_DB(a,b)

"a" is a db or db(...), i.e. a of records. "b" is a field to look for.


>
> Question 3
>
> Somehow I've assumed that when I'm defining a table that it's all DB
> specific, but it seems that I'm also specifiying the GUI presentation --
> pull down menus and so on. Is this correct and intentional?

Yes and not. field.requires sets validators. web2py tries to represent
your field depending on the field type and its validators. This can be
overwritten using field.widget=...

>
> Thank you,
> C. Helck
>
> On Sun, Dec 27, 2009 at 11:55 PM, mdipierro <[email protected]> wrote:
> > 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 <[email protected]>
> > 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 [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<web2py%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/web2py?hl=en.
>
>

--

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


Reply via email to