Skip to content

Models

What is it ?

This folder contains the database table and object models. During the installation process, when the upgrade-db function is used, the database is created dynamically according to the models.

How does it work ?

The models are defined as follows :

# Example

class Category(BaseModel):
    __tablename__ = "categories"

    name = db.Column(db.String(), nullable=False, unique=True)

    # Relationships
    vendors = db.relationship("Vendor", secondary=categories_vendors)
    products = db.relationship("Product", secondary=categories_products)
    users = db.relationship("User", secondary=users_categories)

    @property
    def human_name(self):
        return _humanize_filter(self.name)

    def __repr__(self):
        return "<Category {}>".format(self.name)