"""$Name model.

This is an Asset extension table keyed by assetid. The Asset row holds
the platform fields (assetnumber, name, vendorid, locationid, etc.);
this table holds the $name-specific fields. Replace the example fields
below with your domain model.
"""

from shopdb.extensions import db
from shopdb.core.models.base import BaseModel


class $Name(BaseModel):
    """$Name domain entity, extending Asset by assetid."""

    __tablename__ = '$name'

    assetid = db.Column(
        db.Integer,
        db.ForeignKey('assets.assetid', ondelete='CASCADE'),
        primary_key=True,
    )

    # TODO: replace these example fields with your domain fields.
    examplefield = db.Column(db.String(255), nullable=True)

    asset = db.relationship('Asset', backref=db.backref('$name', uselist=False))

    def to_dict(self):
        return {
            'assetid': self.assetid,
            'examplefield': self.examplefield,
        }
