summaryrefslogtreecommitdiff
path: root/model.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2010-05-04 00:19:40 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2010-05-04 00:19:40 +0200
commit06a8ad9c28502f64112ae8b067028bb6f5fe72b3 (patch)
tree58c20748564b917fe27746c78d5b463cc0cbf4bc /model.py
parent3f19f370ca9f7efcde0955a68f8aa76b46065cd6 (diff)
downloadkosten-06a8ad9c28502f64112ae8b067028bb6f5fe72b3.tar.gz
kosten-06a8ad9c28502f64112ae8b067028bb6f5fe72b3.tar.bz2
kosten-06a8ad9c28502f64112ae8b067028bb6f5fe72b3.zip
Move from DSL to programming style
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()