1
2
3
4
5
6
7
8
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
34
35
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
47
50
51
52 compile_mappers()
53