Skip to main content

Overview

The FurnitureType model represents different categories of furniture products (e.g., tables, chairs, cabinets). It provides categorization for the furniture catalog. Table Name: furniture_type

Fields

Primary Key

id_furniture_type
Integer
required
Unique identifier for the furniture type. Auto-incremented primary key.

Core Fields

name
String(50)
required
Name of the furniture type (e.g., “Table”, “Chair”, “Cabinet”). Must be unique.Constraints:
  • Maximum length: 50 characters
  • Unique: true
  • Nullable: false
active
Boolean
default:"true"
required
Indicates whether the furniture type is active in the system.Default: true

Audit Trail Fields

created_at
TIMESTAMP
required
Timestamp when the furniture type was created.Default: Current timestamp (server-side)
updated_at
TIMESTAMP
required
Timestamp when the furniture type was last updated. Automatically updated on record modification.Default: Current timestamp (server-side)On Update: Automatically set to current timestamp
deleted_at
TIMESTAMP
Timestamp when the furniture type was soft-deleted. NULL if the record is not deleted.
created_by
String(100)
Username or identifier of the user who created the furniture type.
updated_by
String(100)
Username or identifier of the user who last updated the furniture type.
deleted_by
String(100)
Username or identifier of the user who soft-deleted the furniture type.

Methods

to_dict()

Serializes the FurnitureType model instance to a dictionary format suitable for JSON responses. Returns: dict
id_furniture_type
integer
The furniture type’s unique identifier
name
string
The furniture type name
active
boolean
Active status of the furniture type
created_at
string
ISO 8601 formatted creation timestamp
updated_at
string
ISO 8601 formatted last update timestamp
Example Response:
{
  "id_furniture_type": 1,
  "name": "Table",
  "active": true,
  "created_at": "2024-01-15T10:30:00",
  "updated_at": "2024-01-15T10:30:00"
}

Model Source Code

from sqlalchemy.sql import func

from ..extensions import db


class FurnitureType(db.Model):
    """
    Modelo de Tipo de mueble para catálogo de tipo de mueble.

    Attributes:
          id_furniture_type: Identificador único del tipo de mueble.
          name: Nombre del tipo de mueble.
          active: Indica si el tipo de mueble está activo o no.

          created_at: Fecha de creación del tipo de mueble.
          updated_at: Fecha de última actualización del tipo de mueble.
          deleted_at: Fecha de eliminación lógica del tipo de mueble.

          created_by: Usuario que creó el tipo de mueble.
          updated_by: Usuario que actualizó el tipo de mueble.
          deleted_by: Usuario que eliminó el tipo de mueble.
    """

    __tablename__ = 'furniture_type'

    id_furniture_type = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False, unique=True)
    active = db.Column(db.Boolean, nullable=False, default=True)

    created_at = db.Column(
        db.TIMESTAMP,
        nullable=False,
        server_default=func.current_timestamp()
    )
    updated_at = db.Column(
        db.TIMESTAMP,
        nullable=False,
        server_default=func.current_timestamp(),
        server_onupdate=func.current_timestamp()
    )
    deleted_at = db.Column(db.TIMESTAMP, nullable=True)

    created_by = db.Column(db.String(100), nullable=True)
    updated_by = db.Column(db.String(100), nullable=True)
    deleted_by = db.Column(db.String(100), nullable=True)

    def to_dict(self) -> dict:
        """
        Serializa el modelo a diccionario.

        Returns:
            dict: Representación del tipo de mueble en formato diccionario
        """
        return {
            "id_furniture_type": self.id_furniture_type,
            "name": self.name,
            "active": self.active,
            "created_at": self.created_at.isoformat() if self.created_at else None,
            "updated_at": self.updated_at.isoformat() if self.updated_at else None,
        }

Notes

  • The model implements soft delete functionality via the deleted_at field
  • Timestamps are managed automatically by the database
  • The to_dict() method excludes soft-delete audit fields from the response
  • Used for categorizing furniture products in the catalog

Build docs developers (and LLMs) love