60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
"""Sigl Database ORM Setup.
|
|
|
|
Simple Grocery List (Sigl) | sigl.app
|
|
Copyright (c) 2022 Asymworks, LLC. All Rights Reserved.
|
|
"""
|
|
|
|
from sigl.domain.models import Product, ProductLocation
|
|
from sigl.domain.models.list import ListEntry, ShoppingList
|
|
|
|
from .globals import db
|
|
from .tables import list_entries, lists, product_locations, products
|
|
|
|
__all__ = ('init_orm', )
|
|
|
|
|
|
def init_orm():
|
|
"""Initialize the Sigl ORM."""
|
|
# List Entries
|
|
db.mapper(ListEntry, list_entries, properties={
|
|
'product': db.relationship(
|
|
Product,
|
|
back_populates='entries'
|
|
),
|
|
'shoppingList': db.relationship(
|
|
ShoppingList,
|
|
back_populates='entries',
|
|
)
|
|
})
|
|
|
|
# Products
|
|
db.mapper(Product, products, properties={
|
|
'entries': db.relationship(
|
|
ListEntry,
|
|
back_populates='product',
|
|
cascade='all, delete-orphan',
|
|
),
|
|
'locations': db.relationship(
|
|
ProductLocation,
|
|
back_populates='product',
|
|
cascade='all, delete-orphan',
|
|
),
|
|
})
|
|
|
|
# Product Locations
|
|
db.mapper(ProductLocation, product_locations, properties={
|
|
'product': db.relationship(
|
|
Product,
|
|
back_populates='locations',
|
|
)
|
|
})
|
|
|
|
# Shopping Lists
|
|
db.mapper(ShoppingList, lists, properties={
|
|
'entries': db.relationship(
|
|
ListEntry,
|
|
back_populates='shoppingList',
|
|
cascade='all, delete-orphan',
|
|
)
|
|
})
|