Overview
TheRole model manages user roles and permission profiles within the system (e.g., Admin, Editor, Viewer). It provides the foundation for role-based access control (RBAC).
Table Name: roles
Fields
Primary Key
Unique identifier for the role. Auto-incremented primary key.
Core Fields
Name of the role (e.g., “Admin”, “Editor”, “Viewer”). Must be unique.Constraints:
- Maximum length: 50 characters
- Unique: true
- Nullable: false
Indicates whether the role is active in the system.Default:
trueAudit Trail Fields
Timestamp when the role was created.Default: Current timestamp (server-side)
Timestamp when the role was last updated. Automatically updated on record modification.Default: Current timestamp (server-side)On Update: Automatically set to current timestamp
Timestamp when the role was soft-deleted.
NULL if the record is not deleted.Username or identifier of the user who created the role.
Username or identifier of the user who last updated the role.
Username or identifier of the user who soft-deleted the role.
Methods
to_dict()
Serializes the Role model instance to a dictionary format suitable for JSON responses. Returns:dict
The role’s unique identifier
The role name
Active status of the role
ISO 8601 formatted creation timestamp
ISO 8601 formatted last update timestamp
Model Source Code
Notes
- Foundation for implementing role-based access control (RBAC)
- 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 - Typical roles include: Admin, Editor, Viewer, Manager