From 91bb83da81a324727adf1de6190bc747a2f2e3d9 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 4 May 2010 02:22:10 +0200 Subject: Some more relations --- model.py | 13 +++++++++++-- 1 file 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 '' % self.name + if self.parent: + return '' % (self.name, self.parent.name) + else: + return '' % 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 -- cgit v1.2.3-54-g00ecf