models: Add sensible repr

v2
informatic 2017-04-21 17:54:50 +02:00
parent 13e6269969
commit 41e652776d
1 changed files with 6 additions and 0 deletions

View File

@ -20,6 +20,9 @@ class User(db.Model):
def __str__(self):
return self.uid
def __repr__(self):
return '<User {0.uid} {0.balance}>'.format(self)
@hybrid_property
def balance(self):
return sum((_.amount or 0) for _ in self.transactions)
@ -97,3 +100,6 @@ class Transaction(db.Model):
__mapper_args__ = {
"order_by": created.desc()
}
def __repr__(self):
return '<Transaction {0.uid} {0.type} {0.amount} {0.created}>'.format(self)