summaryrefslogtreecommitdiff
path: root/model.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--model.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/model.py b/model.py
index ece69ca..45e9296 100644
--- a/model.py
+++ b/model.py
@@ -1,6 +1,5 @@
import elixir
-from elixir import has_field, belongs_to, has_many, using_options, using_options_defaults
-from elixir import Field, ManyToOne
+from elixir import Field, ManyToOne, ColumnProperty, using_options, using_options_defaults
from sqlalchemy import types as T
from functools import partial
@@ -8,7 +7,7 @@ from functools import partial
elixir.metadata.bind = "sqlite:///test.sqlite"
elixir.metadata.bind.echo = True
-has_req_field = partial(has_field, required = True)
+ReqField = partial(Field, required = True)
class Entity (elixir.Entity):
using_options(abstract = True)
@@ -17,7 +16,7 @@ class Entity (elixir.Entity):
class Category (Entity):
- has_field('name', T.String(50), unique = True)
+ name = Field(T.String(50), unique = True)
def __repr__ (self):
return '<Category "%s">' % self.name
@@ -26,16 +25,18 @@ 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)
+ expense = ReqField(T.Numeric(scale = 2))
+ category = ManyToOne('Category', required = True, innerjoin = True)
class SingleExpense (Expense):
- has_req_field('date', T.Date)
+ date = ReqField(T.Date)
class ConstExpense (Expense):
- has_req_field('months', T.Integer)
- has_req_field('start', T.Date)
- has_req_field('end', T.Date)
+ months = ReqField(T.Integer)
+ start = ReqField(T.Date)
+ end = ReqField(T.Date)
+
+ monthly = ColumnProperty(lambda c: c.expense / c.months)
elixir.setup_all()