Dear all,
I have a question regards many-to-many relationship.
I have the following script:
from sqlalchemy import *
engine=create_engine("postgres://[EMAIL PROTECTED]/NMR2")
metadata=BoundMetaData(engine)
session=create_session()
users=Table('users', metadata, autoload=True)
projects=Table('projects', metadata, autoload=True)
users_projects=Table('users_projects', metadata,
Column('id_users', Integer, ForeignKey('users.id_users')),
Column('id_projects', Integer, ForeignKey('projects.id_projects')),
)
users_projects.create()
class Users(object):
pass
class Projects(object):
pass
umapper=mapper(Users, users)
pmapper=mapper(Projects, projects, properties={
'users' : relation(Users, secondary=users_projects,
backref="projects"), }
)
u=session.query(Users).select()
for i in range(len(u)):
pr=u[i].fk_project.split(',')
for p in range(len(pr)-1):
pname=session.query(Projects).selectfirst(projects.c.id_projects==pr[p])
????????
session.flush()
Actually, the users table has a fk_project field like 1,15,3,. Each
number is an id_projects in projects table. At the moment, this field is
managed by software. Now I want to manage this using a many-to-many
relation and I'm start to write a script to create the table to manage
this new relation.
But I don't understand what I have to put in ??????? to create the
relation. In all examples in the tutorial, the relations are created
using new objects.
Users ha the following fields:
u[0].id_users
u[0].email
u[0].fk_project
u[0].name
u[0].surname
u[0].login
u[0].password
Projects has the following fields:
p[0].id_projects
p[0].project
p[0].state
I tried a lot of sequence without any result.
Someone can help me?
Thanks
-------------------------------------------------------------------
(o_ (o_ //\ Coltivate Linux che tanto Windows si pianta da solo.
(/)_ V_/_
+------------------------------------------------------------------+
| ENRICO MORELLI | email: [EMAIL PROTECTED] |
| * * * * | phone: +39 055 4574269 |
| University of Florence | fax : +39 055 4574253 |
| CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY |
+------------------------------------------------------------------+
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users