Do not let your tables proliferate this way.

You need a teams table, even if it contains only the team name or some 
other identifier.

You need a games table.  

You need to relate these two.  One game has multiple teams, I suppose, so 
that makes a one-to-many relationship.

If the same team can participate in more than one game, you need a many to 
many relationship.

The DAL chapter in the Web2py manual explains how to implement these.

Next you add a game_id field to both your offers and decisions tables. 
 That ties these events to the game.  Alternatively you could simply call 
the field 'game', assuming you can remember that it contains the record id 
of the game in question. 

You also need to add a team_id field to these tables.  That ties each 
record to the team involved.

This data structure will allow you to select records for each game, for 
each team in a game.  If the teams persist, you can also select all the 
records related to the team.

On Sunday, September 30, 2012 5:31:50 PM UTC-4, curiouslearn wrote:
>
> Hello,
>
> This is a question about recommended practice for doing the following:
>
> I want to create a web interface for creating a setup for new games. For 
> example, the web interface will let me specify 
> name of the game, number of teams etc. Based on this information I want to 
> create new database tables for the game.
> Should the table definitions be given in a controller function, such as in 
> the example below? Is that the recommended way
> to do this, or is there another way that you would recommend.
>
> Thank you.
>
> ***Controller function for creating tables***
>
> def createtables():
>     if request.post_vars:
>         experimentname = request.post_vars.experimentname
>         numteams = int(float(request.post_vars.numteams))
>         teams_tablename = "{0}_teams".format(experimentname)
>         offers_tablename = "{0}_offers".format(experimentname)
>         ardecisions_tablename = "{0}_ardecisions".format(experimentname)
>         migrate_teamstablename = "{0}.table".format(teams_tablename)
>         migrate_offerstablename = "{0}.table".format(offers_tablename)
>         migrate_ardecisionstablename = "{0}.table".format(
> ardecisions_tablename)
>         db.define_table(teams_tablename, 
>                 Field('teamname', 'string', length=40, required=True,
>                       unique=True, notnull=True),
>                 Field('passwd', 'password'),
>                 Field('role', 'string', length=20, required=True,
>                       default='NA'),
>                 format = '%(teamname)s', migrate=migrate_teamstablename)
>         # Table showing the ask amount of the first mover
>         referencestring = 'reference {0}'.format(teams_tablename)
>         db.define_table(offers_tablename,
>                         Field('round', 'integer'),
>                         Field('askamount', 'integer'),
>                         Field('payoff', 'integer'),
>                         Field('teamname_id', referencestring),
>                         migrate = migrate_offerstablename)
>
>
>         # Table accept-reject decisions
>         db.define_table(ardecisions_tablename,
>                         Field('round', 'integer'),
>                         Field('acceptorreject', 'string', length=2),
>                         Field('payoff', 'integer'),
>                         Field('teamname_id', referencestring),
>                         Field('offerer_id', referencestring),
>                         migrate = migrate_ardecisionstablename)
>
>
>         teamnames = maketeamnames(numteams)
>         for tname in teamnames:
>             db[teams_tablename].update_or_insert(teamname=tname)
>         db.experimentlist.insert(experimentname=experimentname)
>     return dict()
>
>
>
>

-- 



Reply via email to