Package mcbase :: Package models :: Module objects
[hide private]
[frames] | no frames]

Source Code for Module mcbase.models.objects

 1  # -*- coding: utf-8 -*- 
 2   
 3  ############################################################################ 
 4  # objects.py 
 5  # 
 6  # Database related model objects. 
 7  # 
 8  # (C) 2008 Likya Software Ltd. 
 9  ############################################################################ 
10   
11  import sqlalchemy as sa 
12  from sqlalchemy.orm import relation, backref, compile_mappers 
13  from sqlalchemy.ext.declarative import declarative_base 
14   
15  from mcmodel import MCModel 
16   
17  Base = declarative_base() 
18   
19   
20 -class User(MCModel, Base):
21 __tablename__ = 'users' 22 23 id = sa.Column(sa.Integer, primary_key=True) 24 name = sa.Column(sa.Unicode(12), info={'label': u'Name', 'width': 40}) 25 fullname = sa.Column(sa.Unicode(40), info={'label': u'Full Name', 'width': 100}) 26 password = sa.Column(sa.Unicode(20), info={'label': u'Password', 'width': 60}) 27 active = sa.Column(sa.Boolean(), info={'label': u'Active', 'width': 40}, default=True) 28 type = sa.Column(sa.SmallInteger(), info={'label': u'Type', 'width': 40}) 29 note = sa.Column(sa.Text(), info={'label': u'Note', 'width': 100}) 30 date_created = sa.Column(sa.Date(), info={'label': u'Date', 'width': 80}) 31
32 - def __repr__(self):
33 return "<User([%s] '%s','%s', '%s')>" % (self.id, self.name, self.fullname, self.password)
34 35
36 -class Address(MCModel, Base):
37 __tablename__ = 'addresses' 38 39 id = sa.Column(sa.Integer, primary_key=True) 40 email_address = sa.Column(sa.Unicode(50), nullable=False) 41 user_id = sa.Column(sa.Integer, sa.ForeignKey('users.id')) 42 43 user = relation(User, backref=backref('addresses', order_by=id)) 44
45 - def __init__(self, email_address):
47
48 - def __repr__(self):
49 return "<Address('%s')>" % self.email_address
50 51 52 compile_mappers() 53