Skip to main content

Overview

The WoodType model represents different types of wood available for furniture production. It includes an optional description field, audit trail, and soft delete support. Table Name: wood_types

Fields

Primary Key

id_wood_type
Integer
required
Unique identifier for the wood type. Auto-incremented primary key.

Core Fields

name
String(100)
required
Name of the wood type (e.g., “Oak”, “Pine”, “Walnut”). Must be unique.Constraints:
  • Maximum length: 100 characters
  • Unique: true
  • Nullable: false
description
String(255)
Optional description providing additional details about the wood type.Constraints:
  • Maximum length: 255 characters
  • Nullable: true
active
Boolean
default:"true"
required
Indicates whether the wood type is active in the system.Default: true

Audit Trail Fields

created_at
TIMESTAMP
required
Timestamp when the wood type was created.Default: Current timestamp (server-side)
updated_at
TIMESTAMP
required
Timestamp when the wood 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 wood type was soft-deleted. NULL if the record is not deleted.
created_by
String(100)
Username or identifier of the user who created the wood type.
updated_by
String(100)
Username or identifier of the user who last updated the wood type.
deleted_by
String(100)
Username or identifier of the user who soft-deleted the wood type.

Methods

to_dict()

Serializes the WoodType model instance to a dictionary format. Returns: dict
id_wood_type
integer
The wood type’s unique identifier
name
string
The wood type name
description
string
Optional description of the wood type
active
boolean
Active status of the wood type
created_at
string
Creation timestamp
updated_at
string
Last update timestamp
deleted_at
string
Soft delete timestamp (if applicable)
Example Response:
{
  "id_wood_type": 1,
  "name": "Oak",
  "description": "Durable hardwood with distinctive grain patterns",
  "active": true,
  "created_at": "2024-01-15T10:30:00",
  "updated_at": "2024-01-15T10:30:00",
  "deleted_at": null
}

Model Source Code

from sqlalchemy.sql import func
from ..extensions import db


class WoodType(db.Model):
    """
    Modelo de Tipo de Madera para catálogo de tipos de madera.

    Attributes:
        id_wood_type: Identificador único del tipo de madera.
        name: Nombre del tipo de madera.
        description: Descripción opcional del tipo de madera.
        active: Indica si el tipo de madera está activo o no.

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

        created_by: Usuario que creó el registro.
        updated_by: Usuario que actualizó el registro.
        deleted_by: Usuario que eliminó el registro.
    """

    __tablename__ = 'wood_types'

    id_wood_type = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, unique=True)
    description = db.Column(db.String(255), nullable=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):
        return {
        "id_wood_type": self.id_wood_type,
        "name": self.name,
        "description": self.description,
        "active": self.active,
        "created_at": self.created_at,
        "updated_at": self.updated_at,
        "deleted_at": self.deleted_at,
    }

Notes

  • Unlike other models, to_dict() returns raw timestamp objects instead of ISO formatted strings
  • The model includes an optional description field for additional wood type details
  • Implements soft delete functionality via the deleted_at field
  • The to_dict() method includes the deleted_at field in responses

Build docs developers (and LLMs) love