title: Django: get choices key from display value
body: <p>Let's say I have the following Django model:</p>
  
  <pre><code>class Person(models.Model):
      SHIRT_SIZES = (
          (0, 'Small'),
          (1, 'Medium'),
          (2, 'Large'),
      )
      name = models.CharField(max_length=60)
      shirt_size = models.IntegerField(choices=SHIRT_SIZES)
  </code></pre>
  
  <p>I can create create a <code>Person</code> instance and get the shirt_size <a href="https://docs.djangoproject.com/en/3.0/ref/models/instances/#django.db.models.Model.get_FOO_display" rel="nofollow noreferrer">display value</a> very easily:</p>
  
  <pre><code>john = Person(name="John", shirt_size=2)
  john.shirt_size  # 2
  john.get_shirt_size_display()  # 'Medium'
  </code></pre>
  
  <p>How can I do this the other way? That is, given a shirt size of <code>Medium</code>, how can I get the integer value? I there a method for that or should I write my own method on the <code>Person</code> object like so:</p>
  
  <pre><code>class Person(models.Model):
      ...
  
      @staticmethod
      def get_shirt_size_key_from_display_value(display_value):
      for (key, value) in Person.SHIRT_SIZES:
          if value == display_value:
              return key
          raise ValueError(f"No product type with display value {display_value}")
  </code></pre>