forked from jpsteil/simple_table
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
77 lines (69 loc) · 3.62 KB
/
models.py
File metadata and controls
77 lines (69 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
This file defines the database models
"""
from .common import db, Field
from pydal.validators import *
db.define_table('zip_code',
Field('id', 'id', readable=False),
Field('zip_code', length=5, required=True, unique=True,
requires=[IS_NOT_EMPTY(),
IS_NOT_IN_DB(db, 'zip_code.zip_code')]),
Field('zip_type'),
Field('primary_city'),
Field('state'),
Field('county'),
Field('timezone'),
Field('area_code'),
Field('latitude', 'decimal(5,2)'),
Field('longitude', 'decimal(5,2)'),
format='%(zip_code)s')
db.executesql('CREATE INDEX IF NOT EXISTS zip_code__idx ON zip_code (zip_code);')
db.executesql('CREATE INDEX IF NOT EXISTS zip_code_2__idx ON zip_code (zip_code, county, primary_city);')
db.define_table('company',
Field('name', length=50))
db.define_table('department',
Field('name', length=50))
db.define_table('employee',
Field('first_name', length=50),
Field('last_name', length=50),
Field('company_name', length=50),
Field('address', length=50),
Field('city', length=50),
Field('county', length=50),
Field('state', length=50),
Field('zip_code', length=50),
Field('phone_1', length=50),
Field('phone_2', length=50),
Field('email', length=50),
Field('web', length=50),
Field('supervisor', 'reference employee',
requires=IS_NULL_OR(IS_IN_DB(db, 'employee.id',
'%(last_name)s, %(first_name)s',
zero='..'))),
Field('company', 'reference company',
requires=IS_NULL_OR(IS_IN_DB(db, 'company.id',
'%(name)s',
zero='..'))),
Field('department', 'reference department',
requires=IS_NULL_OR(IS_IN_DB(db, 'department.id',
'%(name)s',
zero='..'))),
Field.Virtual('fullname', lambda x: f'{x.employee.first_name} {x.employee.last_name}'),
Field('hired', 'date', requires=IS_NULL_OR(IS_DATE())),
Field('active', 'boolean', default=False))
db.define_table('contractor',
Field('id', 'id', readable=False),
Field('name'),
Field('position'),
Field('office'),
Field('extension'),
Field('startDate'),
Field('salary'),
format='%(contractor)s')
if not db(db.contractor).count():
db.contractor.insert(name='Martha', position='Software', office='london', extension='1', startDate="2011/07/25", salary=100000)
db.contractor.insert(name='Gavin Cortez', position='Developer', office='london', extension='1', startDate="2011/07/25", salary=100000)
db.contractor.insert(name='Suki Burks', position='Assistant', office='london', extension='1', startDate="2011/07/25", salary=100000)
db.contractor.insert(name='Fiona Green', position='Support', office='london', extension='1', startDate="2011/07/25", salary=100000)
db.contractor.insert(name='Peanut', position='great', office='london', extension='1', startDate="2011/07/25", salary=100000)
db.commit()