Using Django's choices field option


Django tip:

Use choices for character fields with a finite number of possible values.

For example, you can use it for blog's status:

from django.db import models


class Blog(models.Model):
    DRAFT = "DRF"
    PUBLISHED = "PUB"
    DELETED = "DEL"

    STATUS_CHOICES = [
        (DRAFT, "Draft"),
        (PUBLISHED, "Published"),
        (DELETED, "Deleted"),
    ]
    title = models.CharField(max_length=120)
    content = models.TextField()
    contributors = models.TextField()
    status = models.CharField(max_length=3, choices=STATUS_CHOICES, default="DRAFT")