Overview
TheTareas model represents tasks in the system. Each task has a name and is assigned to a single team member. This model inherits from ModeloBase, which provides automatic timestamping and soft delete functionality.
Model Definition
Fields
Direct Fields
The name or title of the task.Constraints:
- Maximum length: 100 characters
- Optional:
null=True, blank=True- can be empty or null
Reference to the team member assigned to this task.Relationship Details:
- References:
encargadomodel - On Delete:
CASCADE- deleting the team member will delete the task - Required field (must be assigned to someone)
Despite the plural name “encargados”, this is a
ForeignKey (one-to-one relationship), not a ManyToManyField. Each task is assigned to exactly one team member.Inherited Fields (from ModeloBase)
The date when the task was created.Constraints:
- Automatically set on creation (
auto_now_add=True) - Read-only after creation
- Verbose name: “Fecha Registro”
The time when the task was created.Constraints:
- Automatically set on creation (
auto_now_add=True) - Read-only after creation
- Verbose name: “Hora Registro”
Indicates whether the task is active or deleted (soft delete).Constraints:
- Default value:
True(active) - Set to
Falsefor soft deletion
Model Relationships
Forward Relationships
Access the team member assigned to this task:
Reverse Relationships
From an
encargado instance, access all tasks assigned to them:Since no
related_name was specified, Django uses the default reverse relationship name: tareas_setString Representation
The model’s__str__() method returns the task name:
Usage Examples
Creating a Task
Querying Tasks
Updating a Task
Soft Deleting a Task
Database Table
This model is stored in the database table:CTP_tareas
Design Considerations
Field Naming: The field
encargados (plural) suggests multiple assignees, but it’s actually a ForeignKey that only allows one assignee per task. Consider this when working with the model.Optional Task Names: Tasks can be created without a name (
null=True, blank=True). Your application logic should handle cases where nombre_tarea is None.