This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/resources/inventory/model.py

23 lines
942 B
Python

from boltons.typeutils import classproperty
from flask import current_app
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.models import Thing
class Inventory(Thing):
__table_args__ = {'schema': 'common'}
id = db.Column(db.Unicode(), primary_key=True)
id.comment = """The name of the inventory as in the URL and schema."""
name = db.Column(db.CIText(), nullable=False, unique=True)
name.comment = """The human name of the inventory."""
tag_provider = db.Column(db.URL(), nullable=False)
tag_token = db.Column(db.UUID(as_uuid=True), unique=True, nullable=False)
tag_token.comment = """The token to access a Tag service."""
org_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey('organization.id'), nullable=False)
@classproperty
def current(cls) -> 'Inventory':
"""The inventory of the current_app."""
return Inventory.query.filter_by(id=current_app.id).one()