Skip to content

Instantly share code, notes, and snippets.

@sheki
Created July 22, 2011 07:45
Show Gist options
  • Save sheki/1099040 to your computer and use it in GitHub Desktop.
Save sheki/1099040 to your computer and use it in GitHub Desktop.
Example model
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