๐Ÿ“ Django

Choices in Django Models

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
579
๐ŸŒฟ
Level
Medium

Use TextChoices to define a model field’s limited set of values in one place for application code, forms, and the Django admin.

TextChoices / IntegerChoices

from django.db import models

class Task(models.Model):
    class Status(models.TextChoices):
        TODO = 'todo', 'To Do'
        IN_PROGRESS = 'in_progress', 'In Progress'
        DONE = 'done', 'Done'

    class Priority(models.IntegerChoices):
        LOW = 1, 'Low'
        MEDIUM = 2, 'Medium'
        HIGH = 3, 'High'

    status = models.CharField(
        max_length=20,
        choices=Status,
        default=Status.TODO,
    )
    priority = models.IntegerField(
        choices=Priority,
        default=Priority.MEDIUM,
    )

Using Choices

# Creating
task = Task.objects.create(status=Task.Status.TODO, priority=Task.Priority.HIGH)

# Filtering
Task.objects.filter(status=Task.Status.DONE)

# Human-readable value
task.get_status_display()  # 'To Do'
task.get_priority_display()  # 'High'

# Iterating over options
for value, label in Task.Status.choices:
    print(value, label)

In a Template

<span>{{ task.get_status_display }}</span>

<select name="status">
  {% for value, label in status_choices %}
    <option value="{{ value }}">{{ label }}</option>
  {% endfor %}
</select>

Old Style (without enum)

STATUS_CHOICES = [
    ('todo', 'To Do'),
    ('done', 'Done'),
]
status = models.CharField(choices=STATUS_CHOICES, max_length=20)

TextChoices is preferred โ€” it provides autocompletion and avoids magic strings.

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

Search in Django

You can start with simple Django ORM filters and move to PostgreSQL features when you...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 279
๐Ÿ“

Swagger Documentation with drf-spectacular

drf-spectacular generates an OpenAPI 3.0 schema and Swagger UI for DRF.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 563
๐Ÿ“

settings.py: Django Configuration

settings.py is the central configuration file for a Django project.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 315

Did you like the article?

Subscribe to our updates and be the first to receive new articles. Grow with PyLand!