Thanks, stifan, that got me half the way there. Now, tables *sessions* and
*programs_players* are both showing program in desired format, rather than
IDs.
The only trouble I'm having now is with the table named *sessions_players*.
It is still showing the program ID rather than the program "name", which is
formatted as a concatenation of the program_type and the age_gender_group.
In other posts, Anthony has pointed out that format doesn't propagate
beyond the first referenced table, but that one can use a requires
statement instead (and he's also pointed out that that's inefficient and
costly for larger data sets, recommending the use of a query to generate
options for IS_IN_SET).
I'm going to try the requires approach for now, since my data is tiny.
db.define_table('age_gender_groups',
Field('age', 'string'), # eg: U10s, U12s, high school,
junior high, U16s, et c.
Field('gender', 'string',
requires=IS_IN_SET(['girls','boys', 'mixed'], zero=None)),
format = lambda r: '%s %s' % (r.age, r.gender)
)
db.define_table('program_types',
Field('name', 'string'),
Field('stratum', 'integer'),
format = lambda r: '%s' % (r.name)
)
db.define_table('programs',
Field('program_type', 'reference program_types'),
Field('age_group', 'reference age_gender_groups'),
Field('date_start', 'date'),
Field('date_end', 'date'),
Field('coach', 'reference auth_user'),
Field('assistant', 'reference auth_user'),
Field('squad', 'integer', default=1), # to be able
to sub-divide programs so as to manage size
format = lambda r: '%s %s %s' % (r.program_type.name,
r.age_group.age, r.age_group.gender) # squad# %(squad)s'
)
db.programs._format = lambda r: '%s %s %s' % (r.program_type.name,
r.age_group.age, r.age_group.gender)
query_programs = (
(db.auth_user.id == db.auth_membership.user_id) &
(db.auth_membership.group_id == db.auth_group.id) &
(db.auth_group.role.like('coach'))
)
db.programs.coach.requires = IS_IN_DB(db(query_programs), db.auth_user.id,
'%(first_name)s %(last_name)s')
db.programs.assistant.requires = IS_IN_DB(db(query_programs),
db.auth_user.id, '%(first_name)s %(last_name)s')
db.define_table('sessions',
Field('program_name', 'reference programs'),
Field('session_type', 'string',
requires=IS_IN_SET(['practice', 'evaluation'], zero=None)),
Field('coach', 'reference auth_user'),
Field('assistant', 'reference auth_user'),
Field('session_date_time', 'datetime'),
format = lambda r: '%s at %s on %s' % (r.program_name,
datetime.time(r.session_date_time), datetime.date(r.session_date_time))
)
query_sessions = (
(db.auth_user.id == db.auth_membership.user_id) &
(db.auth_membership.group_id == db.auth_group.id) &
(db.auth_group.role.like('coach'))
)
db.sessions.coach.requires = IS_IN_DB(db(query_sessions), db.auth_user.id,
'%(first_name)s %(last_name)s')
db.sessions.assistant.requires = IS_IN_DB(db(query_sessions),
db.auth_user.id, '%(first_name)s %(last_name)s')
db.define_table('programs_players', # lists players attached to various
programs
Field('program_name', 'reference programs'),
Field('player', 'reference auth_user')
)
query_programs_players = (
(db.auth_user.id == db.auth_membership.user_id) &
(db.auth_membership.group_id == db.auth_group.id) &
(db.auth_group.role.like('player'))
)
db.programs_players.player.requires = IS_IN_DB(db(query_programs_players),
db.auth_user.id, '%(first_name)s %(last_name)s')
db.programs_players.player.represent = lambda id, row:
(db.auth_user(id).first_name + ' ' + db.auth_user(id).last_name) if
id!=None else 'N/A'
db.define_table('sessions_players', # record player attendance at a
session, whether it is a practice or an evaluation
Field('session_name', 'reference sessions'),
Field('player', 'reference auth_user'),
Field('presence', 'string', default='present',
requires=IS_IN_SET(['expected','present','absent'], zero=None))
)
query_sessions_players = (
(db.auth_user.id == db.auth_membership.user_id) &
(db.auth_membership.group_id == db.auth_group.id) &
(db.auth_group.role.like('player'))
)
db.sessions_players.player.requires = IS_IN_DB(db(query_sessions_players),
db.auth_user.id, '%(first_name)s %(last_name)s')
db.sessions_players.player.represent = lambda id, row:
(db.auth_user(id).first_name + ' ' + db.auth_user(id).last_name) if
id!=None else 'N/A'
--
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/d/optout.