From 06a8ad9c28502f64112ae8b067028bb6f5fe72b3 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 4 May 2010 00:19:40 +0200 Subject: Move from DSL to programming style --- model.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'model.py') 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 '' % 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() -- cgit v1.2.3-70-g09d2