Overview
TheUnitOfMeasure model represents units of measurement used throughout the furniture store system (e.g., cm, m, kg, pieces). Each unit includes both a full name and an abbreviation.
Table Name: unit_of_measures
Fields
Primary Key
Unique identifier for the unit of measure. Auto-incremented primary key.
Core Fields
Full name of the unit (e.g., “Centimeter”, “Kilogram”). Must be unique.Constraints:
- Maximum length: 50 characters
- Unique: true
- Nullable: false
Abbreviated form of the unit (e.g., “cm”, “kg”, “pcs”). Must be unique.Constraints:
- Maximum length: 10 characters
- Unique: true
- Nullable: false
Indicates whether the unit of measure is active in the system.Default:
trueAudit Trail Fields
Timestamp when the unit of measure was created.Default: Current timestamp (server-side)
Timestamp when the unit of measure was last updated. Automatically updated on record modification.Default: Current timestamp (server-side)On Update: Automatically set to current timestamp
Timestamp when the unit of measure was soft-deleted.
NULL if the record is not deleted.Username or identifier of the user who created the unit of measure.
Username or identifier of the user who last updated the unit of measure.
Username or identifier of the user who soft-deleted the unit of measure.
Methods
to_dict()
Serializes the UnitOfMeasure model instance to a dictionary format suitable for JSON responses. Returns:dict
The unit’s unique identifier
The full name of the unit
The abbreviated form of the unit
Active status of the unit
ISO 8601 formatted creation timestamp
ISO 8601 formatted last update timestamp
Model Source Code
Notes
- Both
nameandabbreviationfields must be unique - The model implements soft delete functionality via the
deleted_atfield - Timestamps are managed automatically by the database
- The
to_dict()method excludes soft-delete audit fields from the response - Commonly used for dimensions (cm, m, in) and quantities (pcs, kg, lb)