Hi,
I have an existing piece of functionality but I am wondering if there
are ways to improve the code. A short summary what I have. I modelled
a person class which can have different roles, one being a student
role, another one being an employee role, an alumni role and so on.
Now I am trying to retrieve all persons which have an employee role
but only those that do not have the alumni role.
This is what I came up with:
query = session.query(Person).join('roles')
alumnis =
query.filter(Role.roleID==alumni_table.c.roleID).order_by(Person.lastName).all()
tmp = query.filter(Role.roleID==employee_table.c.roleID).all()
employees = list(set(tmp) - set(alumnis))
employees.sort(key=operator.attrgetter('lastName'))
It is working as expected but I thought there must be better ways to
do it. Instead of letting python do the work I would like to pass this
to sql. I found except_ in the sql expression api but I do not know
where to start with that. So if there is somebody out there who has a
smart idea how to improve the code, let me know...
Thanks and Greetings, Jan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---