bitvend/models: rewrite purchase_count/purchase_amount
parent
ad24d2684d
commit
12dd471725
|
@ -70,17 +70,11 @@ class User(db.Model):
|
|||
.correlate_except(Transaction)
|
||||
)
|
||||
|
||||
@hybrid_property
|
||||
def purchase_count(self):
|
||||
return self.transactions.filter(Transaction.type == "purchase").count()
|
||||
|
||||
@purchase_count.expression
|
||||
def purchase_count(self):
|
||||
return (
|
||||
select([func.count(Transaction.amount)])
|
||||
.where(and_(Transaction.uid == User.uid, Transaction.type == "purchase"))
|
||||
.label("purchase_count")
|
||||
)
|
||||
purchase_count = column_property(
|
||||
select([func.count(Transaction.amount)])
|
||||
.where(and_(Transaction.uid == uid, Transaction.type == "purchase"))
|
||||
.correlate_except(Transaction)
|
||||
)
|
||||
|
||||
@hybrid_property
|
||||
def purchase_amount(self):
|
||||
|
@ -89,13 +83,11 @@ class User(db.Model):
|
|||
for tx in self.transactions.filter(Transaction.type == "purchase")
|
||||
)
|
||||
|
||||
@purchase_amount.expression
|
||||
def purchase_amount(self):
|
||||
return (
|
||||
select([-func.sum(Transaction.amount)])
|
||||
.where(and_(Transaction.uid == User.uid, Transaction.type == "purchase"))
|
||||
.label("purchase_amount")
|
||||
)
|
||||
purchase_amount = column_property(
|
||||
select([-func.sum(Transaction.amount)])
|
||||
.where(and_(Transaction.uid == uid, Transaction.type == "purchase"))
|
||||
.correlate_except(Transaction)
|
||||
)
|
||||
|
||||
def transfer(self, target, amount):
|
||||
if amount > self.amount_available:
|
||||
|
|
Loading…
Reference in New Issue