Models

get_<field>_display()

  • django automatically generates a method for each field with choices
  • this method returns the human-readable label linked with the choice. see also django model field choices
class YourModel(models.Model):
    STATUS_CHOICES = [
        ('draft', 'Draft'),
        ('published', 'Published'),
        ('archived', 'Archived'),
    ]
    status = models.CharField(max_length=20, choices=STATUS_CHOICES)
instance = YourModel.objects.get(pk=1)
 
# This will print 'Draft', 'Published', or 'Archived'
print(instance.get_status_display())