Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado.consts import READ
from awokado.meta import ResourceMeta
from awokado.resource import BaseResource
class StoreStatsResource(BaseResource):
Meta = ResourceMeta(
model=m.Store,
name="store_stats",
methods=(READ,),
select_from=sa.outerjoin(
m.Store, m.Book, m.Store.id == m.Book.store_id
),
)
name = fields.String(model_field=m.Store.name)
books_count = fields.Int(
dump_only=True, model_field=sa.func.count(m.Book.id)
)
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado.consts import READ
from awokado.meta import ResourceMeta
from awokado.resource import BaseResource
class TagStatsResource(BaseResource):
Meta = ResourceMeta(
model=m.Tag,
name="tag_stats",
methods=(READ,),
disable_total=True,
select_from=sa.outerjoin(
m.Tag, m.M2M_Book_Tag, m.Tag.id == m.M2M_Book_Tag.c.tag_id
).outerjoin(m.Book, m.M2M_Book_Tag.c.book_id == m.Book.id),
id_field="name",
)
name = fields.String(model_field=m.Tag.name)
books_count = fields.Int(
dump_only=True, model_field=sa.func.count(m.Book.id)
)