Task Results and Status in Django
📖 Scenario: You are building a simple Django app to track tasks and their results. Each task has a name and a status that shows if it is pending, completed, or failed.
🎯 Goal: Create a Django model to store tasks with their results and status. Then, configure a status choice field, write a query to filter completed tasks, and finally add a method to display the task status nicely.
📋 What You'll Learn
Create a Django model named
Task with fields name (CharField) and status (CharField).Define a
STATUS_CHOICES tuple with values 'pending', 'completed', and 'failed'.Write a Django ORM query to get all tasks with status
'completed'.Add a method
get_status_display in the Task model to return a user-friendly status string.💡 Why This Matters
🌍 Real World
Tracking task status is common in project management, bug tracking, and workflow automation apps.
💼 Career
Understanding Django models, choices, and queries is essential for backend web development jobs using Django.
Progress0 / 4 steps