Thanks nils, I will give that a try when I get home from work. I had another idea that I will try out as well...leaving it here for my reference later.
create the players.team field, but also leave in the players.teamname (string) add a false id value for all players (0 in this case will probably work) import team and players tables join on players.teamname with teams.name (ugly, but I should only have to do it once) copy the teams.id to the players.team for each row On Jan 25, 12:48 pm, nils <[email protected]> wrote: > Hi, > I had a similar problem, > > my solution was somthing like this: > > import csv > > dr = csv.DictReader(open('csvfile.csv'), delimiter=',') > > for data in dr: > if data['team'] =='text': > team = 1 or (the team id in your table) > elif data['team'] =='more text': > team = 2 or (the team id in your table) > db.teams.insert(name=team) > > On Wed, Jan 25, 2012 at 1:57 PM, vtgorilla > > > > > > > > <[email protected]> wrote: > > Hi, first post so go easy on me! > > > I have two tables setup as shown below. I have a lot of data > > (thousands of lines) that I'd like to import, but I can't seem to > > figure out an easy way to relate the players.team field back to a team > > in the teams table without modifying thousands of lines in excel, one > > by one, to have the matching ID for a team rather than the matching > > text (both csv files contain teams.name). > > > db.define_table('teams', > > Field('name', unique=True),...) > > > db.define_table('players', > > Field('team', 'reference teams'),...) > > > db.players.team.requires = IS_IN_DB(db, db.teams.id, '%(name)s') > > > So my question is...is there a way to csv import my players and have > > w2p or sql recognize the matching team name and assign the > > corresponding teams.id in the table? It seems to work this way if I > > add one at a time from the interface, but obviously that would be > > impractical with such a large number of items. > > > Thanks for you help and let me know if that wasn't clear enough! > > Brad

