Created
July 22, 2011 07:45
-
-
Save sheki/1099040 to your computer and use it in GitHub Desktop.
Example model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import Table, Column, Integer, String, ForeignKey | |
from sqlalchemy.orm import mapper | |
from database import metadata, db_session | |
class Team( object ): | |
query = db_session.query_property() | |
def __init__(self, name=None): | |
self.name = name | |
def __repr__(self): | |
return '<User %r>' % (self.name) | |
class Package( object ) : | |
query = db_session.query_property() | |
def __init__ (self, name =None ): | |
self.name = name | |
def __repr__ (self) : | |
return '<Package %r>' % (self.name) | |
teams = Table('teams', metadata, | |
Column('id',Integer, primary_key=True), | |
Column('name', String(50), unique=True) | |
) | |
packages = Table ('packages' , metadata, | |
Column( 'id',Integer,primary_key=True), | |
Column( 'name',String(50), unique=True ) , | |
Column( 'teamid',Integer, ForeignKey('teams.id')), | |
) | |
mapper(Team, teams) | |
mapper(Package, packages ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment