Updated doc blocks
This commit is contained in:
@@ -45,7 +45,7 @@ Simple aggregates
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
from sqlalchemy_utils import aggregated_attr
|
from sqlalchemy_utils import aggregated
|
||||||
|
|
||||||
|
|
||||||
class Thread(Base):
|
class Thread(Base):
|
||||||
@@ -53,9 +53,9 @@ Simple aggregates
|
|||||||
id = sa.Column(sa.Integer, primary_key=True)
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
name = sa.Column(sa.Unicode(255))
|
name = sa.Column(sa.Unicode(255))
|
||||||
|
|
||||||
@aggregated_attr('comments')
|
@aggregated('comments', sa.Column(sa.Integer))
|
||||||
def comment_count(self):
|
def comment_count(self):
|
||||||
return sa.Column(sa.Integer)
|
return sa.func.count('1')
|
||||||
|
|
||||||
comments = sa.orm.relationship(
|
comments = sa.orm.relationship(
|
||||||
'Comment',
|
'Comment',
|
||||||
@@ -79,7 +79,7 @@ Custom aggregate expressions
|
|||||||
::
|
::
|
||||||
|
|
||||||
|
|
||||||
from sqlalchemy_utils import aggregated_attr
|
from sqlalchemy_utils import aggregated
|
||||||
|
|
||||||
|
|
||||||
class Catalog(Base):
|
class Catalog(Base):
|
||||||
@@ -87,15 +87,10 @@ Custom aggregate expressions
|
|||||||
id = sa.Column(sa.Integer, primary_key=True)
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
name = sa.Column(sa.Unicode(255))
|
name = sa.Column(sa.Unicode(255))
|
||||||
|
|
||||||
@aggregated_attr
|
@aggregated('products', sa.Column(sa.Integer))
|
||||||
def net_worth(self):
|
|
||||||
return sa.Column(sa.Integer)
|
|
||||||
|
|
||||||
@net_worth.expression
|
|
||||||
def net_worth(self):
|
def net_worth(self):
|
||||||
return sa.func.sum(Product.price)
|
return sa.func.sum(Product.price)
|
||||||
|
|
||||||
|
|
||||||
products = sa.orm.relationship('Product')
|
products = sa.orm.relationship('Product')
|
||||||
|
|
||||||
|
|
||||||
@@ -163,7 +158,7 @@ to define lots of relationships pointing to same class, remember to define the r
|
|||||||
::
|
::
|
||||||
|
|
||||||
|
|
||||||
from sqlalchemy_utils import aggregated_attr
|
from sqlalchemy_utils import aggregated
|
||||||
|
|
||||||
|
|
||||||
class Customer(Base):
|
class Customer(Base):
|
||||||
@@ -171,23 +166,14 @@ to define lots of relationships pointing to same class, remember to define the r
|
|||||||
id = sa.Column(sa.Integer, primary_key=True)
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
name = sa.Column(sa.Unicode(255))
|
name = sa.Column(sa.Unicode(255))
|
||||||
|
|
||||||
@aggregated_attr('orders')
|
@aggregated('orders', sa.Column(sa.Integer))
|
||||||
def orders_sum(self):
|
|
||||||
return sa.Column(sa.Integer)
|
|
||||||
|
|
||||||
@orders_sum.expression
|
|
||||||
def orders_sum(self):
|
def orders_sum(self):
|
||||||
return sa.func.sum(Order.price)
|
return sa.func.sum(Order.price)
|
||||||
|
|
||||||
@aggregated_attr('invoiced_orders')
|
@aggregated('invoiced_orders', sa.Column(sa.Integer))
|
||||||
def invoiced_orders_sum(self):
|
|
||||||
return sa.Column(sa.Integer)
|
|
||||||
|
|
||||||
@invoiced_orders_sum.expression
|
|
||||||
def invoiced_orders_sum(self):
|
def invoiced_orders_sum(self):
|
||||||
return sa.func.sum(Order.price)
|
return sa.func.sum(Order.price)
|
||||||
|
|
||||||
|
|
||||||
orders = sa.orm.relationship('Order')
|
orders = sa.orm.relationship('Order')
|
||||||
|
|
||||||
invoiced_orders = sa.orm.relationship(
|
invoiced_orders = sa.orm.relationship(
|
||||||
@@ -216,7 +202,7 @@ Multi-level aggregates
|
|||||||
::
|
::
|
||||||
|
|
||||||
|
|
||||||
from sqlalchemy_utils import aggregated_attr
|
from sqlalchemy_utils import aggregated
|
||||||
|
|
||||||
|
|
||||||
class Catalog(Base):
|
class Catalog(Base):
|
||||||
@@ -224,15 +210,10 @@ Multi-level aggregates
|
|||||||
id = sa.Column(sa.Integer, primary_key=True)
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
name = sa.Column(sa.Unicode(255))
|
name = sa.Column(sa.Unicode(255))
|
||||||
|
|
||||||
@aggregated_attr('categories.products')
|
@aggregated('categories.products', sa.Column(sa.Integer))
|
||||||
def net_worth(self):
|
|
||||||
return sa.Column(sa.Integer)
|
|
||||||
|
|
||||||
@net_worth.expression
|
|
||||||
def net_worth(self):
|
def net_worth(self):
|
||||||
return sa.func.sum(Product.price)
|
return sa.func.sum(Product.price)
|
||||||
|
|
||||||
|
|
||||||
categories = sa.orm.relationship('Product')
|
categories = sa.orm.relationship('Product')
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user