summaryrefslogtreecommitdiff
path: root/model.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--model.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/model.py b/model.py
index af2a97e..867849f 100644
--- a/model.py
+++ b/model.py
@@ -52,9 +52,10 @@ class Expense (Entity):
category = ManyToOne('Category', required = True, innerjoin = True)
class SingleExpense (Expense):
- year = ReqField(T.Integer)
- month = ReqField(T.SmallInteger)
- day = ReqField(T.SmallInteger)
+ date = ReqField(T.Date)
+
+ year = ColumnProperty(lambda c: sql.extract('year', c.date))
+ month = ColumnProperty(lambda c: sql.extract('month', c.date))
@classmethod
def of_month (cls, month, year):
@@ -65,17 +66,21 @@ class SingleExpense (Expense):
return cls.query.filter(comp)
class ConstExpense (Expense):
- months = ReqField(T.SmallInteger)
- start_year = ReqField(T.Integer)
- start_month = ReqField(T.SmallInteger)
- end_year = ReqField(T.Integer)
- end_month = ReqField(T.SmallInteger)
+ months = ReqField(T.Integer)
+ start = ReqField(T.Date)
+ end = ReqField(T.Date)
next = OneToOne('ConstExpense', inverse = 'prev')
prev = ManyToOne('ConstExpense')
monthly = ColumnProperty(lambda c: sql.cast(c.expense / c.months, ExpNum), deferred = True)
+ start_year = ColumnProperty(lambda c: sql.extract('year', c.start))
+ start_month = ColumnProperty(lambda c: sql.extract('month', c.start))
+
+ end_year = ColumnProperty(lambda c: sql.extract('year', c.end))
+ end_month = ColumnProperty(lambda c: sql.extract('month', c.end))
+
@classmethod
def of_month (cls, month, year):
c1 = sql.or_(