title: How can I access a Django model's Enum from within a template?
body: <p>My Django model class is as follows:</p>
  
  <pre><code>class MyClass(models.Model):
      CHOICE1 = "CHOICE1"
      CHOICE2 = "CHOICE2"
  
      FIELD_CHOICES = (
          (CHOICE1, CHOICE1),
          (CHOICE2, CHOICE2),
      )
      my_field = models.CharField(
          max_length=254,
          null=False,
          blank=False,
          choices=FIELD_CHOICES,
          default=CHOICE1,
      )
  </code></pre>
  
  <p>I pass <code>my_instance</code> which is an instance of <code>MyClass</code> into the template. 
  From within that template how can I do an if-else check on the possible values of my_field?</p>
  
  <p>I do the following, but it doesn't work:</p>
  
  <pre><code>{% if my_instance.my_field == my_instance.__class__.CHOICE1 %}
      &lt;p&gt;BLAH BLAH1&lt;/p&gt;
  {% elif my_instance.my_field == my_instance.__class__.CHOICE2 %}
      &lt;p&gt;BLAH BLAH2&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I can pass the class <code>MyClass</code> into the template context and then use <code>MyClass.CHOICEX</code>. That works. But it seems wasteful to have to pass in the class itself in addition to the instance. Can't I get the Class from the instance and then use <code>CHOICEX</code>?</p>