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
|
import elixir
from elixir import has_field, belongs_to, has_many, using_options, using_options_defaults
from elixir import Field, ManyToOne
from sqlalchemy import types as T
from functools import partial
elixir.metadata.bind = "sqlite:///test.sqlite"
elixir.metadata.bind.echo = True
has_req_field = partial(has_field, required = True)
class Entity (elixir.Entity):
using_options(abstract = True)
using_options_defaults(shortnames = True)
class Category (Entity):
has_field('name', T.String(50), unique = True)
def __repr__ (self):
return '<Category "%s">' % self.name
class Expense (Entity):
using_options(abstract = True)
description = Field(T.String(50))
expense = Field(T.Numeric(scale = 2), required = True)
category = ManyToOne('Category', required = True, innerjoin = True, lazy = False)
class SingleExpense (Expense):
has_req_field('date', T.Date)
class ConstExpense (Expense):
has_req_field('months', T.Integer)
has_req_field('start', T.Date)
has_req_field('end', T.Date)
elixir.setup_all()
session = elixir.session
if __name__ == "__main__":
elixir.create_all()
|