Overview
Theencargado model represents team members or managers in the system. Team members can be assigned as project leaders, project team members, and task assignees. This model inherits from ModeloBase, which provides automatic timestamping and soft delete functionality.
Model Definition
Fields
Direct Fields
The name(s) of the team member.Constraints:
- Maximum length: 100 characters
- Optional:
null=True, blank=True- can be empty or null
Inherited Fields (from ModeloBase)
Theencargado model inherits the following fields from the abstract ModeloBase class:
The date when the team member was registered.Constraints:
- Automatically set on creation (
auto_now_add=True) - Read-only after creation
- Verbose name: “Fecha Registro”
The time when the team member was registered.Constraints:
- Automatically set on creation (
auto_now_add=True) - Read-only after creation
- Verbose name: “Hora Registro”
Indicates whether the team member is active or deleted (soft delete).Constraints:
- Default value:
True(active) - Set to
Falsefor soft deletion
ModeloBase Abstract Model
TheModeloBase abstract model provides common fields for all models in the system:
The
ModeloBase model is abstract and does not create its own database table. It only provides fields to models that inherit from it.Model Relationships
While theencargado model has no forward relationships (foreign keys), it has several important reverse relationships:
Reverse Relationships
Access all projects where this team member is the leader:Relationship Details:
- Related from:
Proyectos.liderfield - Type: One-to-Many (one leader can lead many projects)
Access all projects where this team member is assigned (not necessarily as leader):Relationship Details:
- Related from:
Proyectos.encargadosfield - Type: Many-to-Many (team member can be on many projects, projects can have many team members)
Access all tasks assigned to this team member:Relationship Details:
- Related from:
Tareas.encargadosfield - Type: One-to-Many (one team member can have many tasks)
- Uses default reverse name since no
related_namespecified
String Representation
The model’s__str__() method returns the team member’s name:
Usage Examples
Creating a Team Member
Querying Team Members
Accessing Related Projects and Tasks
Checking Workload
Soft Deleting a Team Member
Database Table
This model is stored in the database table:CTP_encargado
Best Practices
Soft Delete Pattern: The
status field implements a soft delete pattern. Instead of permanently deleting records, set status=False to maintain referential integrity and historical data.Timestamp Tracking: The
fecha_registro and hora_registro fields automatically track when each team member was created. These fields are read-only and cannot be modified after creation.Optional Names: Team members can be created without a name (
null=True, blank=True). Your application logic should handle cases where nombres is None.