From 4a0e05eae82148a6430052769037e131987c81a4 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 11 Jun 2015 23:30:20 +0200 Subject: [PATCH] Add class methods for get by id in models. --- accountant/api/models/accounts.py | 4 ++++ accountant/api/models/entries.py | 4 ++++ accountant/api/models/operations.py | 4 ++++ accountant/api/models/scheduled_operations.py | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/accountant/api/models/accounts.py b/accountant/api/models/accounts.py index 1bb7d6c..0255b8d 100644 --- a/accountant/api/models/accounts.py +++ b/accountant/api/models/accounts.py @@ -44,3 +44,7 @@ class Account(db.Model): ).outerjoin(Entry).group_by(cls.id).order_by(cls.id) return query + + @classmethod + def get(cls, session, id): + return session.query(cls).filter(cls.id == id).one() diff --git a/accountant/api/models/entries.py b/accountant/api/models/entries.py index df64e8d..cd8e052 100644 --- a/accountant/api/models/entries.py +++ b/accountant/api/models/entries.py @@ -62,3 +62,7 @@ class Entry(db.Model): ).filter(cls.account_id == account_id).order_by("year", "month") return query + + @classmethod + def get(cls, session, id): + return session.query(cls).filter(cls.id == id).one() diff --git a/accountant/api/models/operations.py b/accountant/api/models/operations.py index 3b212fd..0fe296b 100644 --- a/accountant/api/models/operations.py +++ b/accountant/api/models/operations.py @@ -95,3 +95,7 @@ class Operation(db.Model): ).group_by(cls.account_id) return query + + @classmethod + def get(cls, session, id): + return session.query(cls).filter(cls.id == id).one() diff --git a/accountant/api/models/scheduled_operations.py b/accountant/api/models/scheduled_operations.py index 4eaad97..f8a2a51 100644 --- a/accountant/api/models/scheduled_operations.py +++ b/accountant/api/models/scheduled_operations.py @@ -67,3 +67,7 @@ class ScheduledOperation(db.Model): ) return query + + @classmethod + def get(cls, session, id): + return session.query(cls).filter(cls.id == id).one()