summaryrefslogtreecommitdiff
path: root/model.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--model.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/model.py b/model.py
index 45e9296..02323b9 100644
--- a/model.py
+++ b/model.py
@@ -1,5 +1,5 @@
import elixir
-from elixir import Field, ManyToOne, ColumnProperty, using_options, using_options_defaults
+from elixir import Field, ManyToOne, OneToMany, OneToOne, ColumnProperty, using_options, using_options_defaults
from sqlalchemy import types as T
from functools import partial
@@ -18,8 +18,14 @@ class Category (Entity):
name = Field(T.String(50), unique = True)
+ parent = ManyToOne('Category')
+ children = OneToMany('Category')
+
def __repr__ (self):
- return '<Category "%s">' % self.name
+ if self.parent:
+ return '<Category "%s" of "%s">' % (self.name, self.parent.name)
+ else:
+ return '<Category "%s">' % self.name
class Expense (Entity):
using_options(abstract = True)
@@ -38,6 +44,9 @@ class ConstExpense (Expense):
monthly = ColumnProperty(lambda c: c.expense / c.months)
+ next = OneToOne('ConstExpense', inverse = 'prev')
+ prev = ManyToOne('ConstExpense')
+
elixir.setup_all()
session = elixir.session