On Wed, Mar 11, 2009 at 5:13 PM, rev <[email protected]> wrote: > > Hi, > > I just made my first babysteps with TG2. > Still juggling with a lot of info in my head, and trying to pick out > the relevant bits to get basic stuff working. > > I have a model with a User and a Group, each having an id and some > other fields. > I've a many-to-many relation setup with > user_group_table = Table('user_p4group', metadata, > Column('user_id', Integer, ForeignKey > ('users.id')), > Column('group_id', Integer, ForeignKey > ('groups.id')) > ) > This is all working fine. > > I need to pre-populate my db with some data that originates from > another application. > I have a list with group id's, a list of user id's, and for each group > a list of its members. > The group list is read, and for each group I do > g = model.Group() > g.field1 = .. > g.field2 = .. > model.DBSession.add(g) > Same for the users. > So far, so good. > > Then comes the lists of groups and their members. > g = model.DBSession.query(model.Group).filter_by(group='groupid- > from-list').first() > <foreach user in grouplist>: > u = model.DBSession.query(model.User).filter_by(user='userid- > from-list').first() > g.users.append(u)
that is one way of doing it. if you are worried about performance it could be improved but since this seems like a one time import looks good. > > Is this how it should be done, or are you wetting your pants from > laughing? > hehe > Cheers, > Rene > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

