Hey Everyone, So my problem is this. In my application admins are able to create discussion groups and invite users to join them, so I have made a form to do that. For various reasons I decided to make my own tables to keep track of groups and members of the groups instead of using the built in web2py ones. The problem is the drop down list on the form shows all the users even if they are already part of the discussion group, so you are able to add a user more then once which creates duplicate records. I've tried filtering the records displayed in the drop down, by using IS_IN_DB(db, db.table_name, query) but then the drop down doesn't display any records at all. I've also tried using IS_NOT_IN_DB(), but then the form doesn't have a drop down, instead it uses a text input box for the users field. I basically want to filter the records so that only users who are not already a member of the group are in the drop down, how can I do this?. Here's my code
Table definitions ### user groups ### """ Defined our own user groups and member_of tables. The built in web2py ones are still used for administration stuff, but we decided to separate these ones for wrighthubs different groups """ db.define_table('wrighthub_groups', Field('name', 'string', requires=IS_NOT_EMPTY()), Field('created_on', 'datetime', writable=False), Field('created_by', 'reference auth_user', writable=False), Field('description', 'text', requires=IS_NOT_EMPTY()), Field('group_info', 'text') ) ### Members of groups ### db.define_table('member_of', Field('user', 'reference auth_user'), Field('user_group', 'reference wrighthub_groups', requires=IS_IN_DB(db, db.wrighthub_groups, '%(name)s')), Field('role', 'string', requires=IS_IN_SET(MEMBER_ROLES)), Field('status', 'string', requires=IS_IN_SET(STATUSES)) ) Controller code ### A page that shows a specific group ### @auth.requires_membership('Administrator') def show_group(): group_id = request.args(0, cast=int) group = db(db.wrighthub_groups.id == group_id).select().first() #query all the users not in the current group * in_group = db(db.member_of.user_group==group_id)._select(db.member_of.user)* * users = ~(db.auth_user.id.belongs(in_group))* * db.member_of.user.requires = IS_IN_DB(db, db.member_of, users)* #Set the default for some of the form fields and make them not visible db.member_of.user_group.default = group_id db.member_of.user_group.readable = False db.member_of.user_group.writable = False db.member_of.status.default = "Pending" db.member_of.status.readable = False db.member_of.status.writable = False #some code to create the form here Any help would be much appreciated. Thanks, Ari -- 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/d/optout.