title: Template filter + if tag
body: <p>I have applied a template filter, which extracts the domain from an email address. In the template file I have this code:</p>
  
  <pre><code>{% for email in user_list %}
  
  &lt;p&gt; 
  {{email.email}} corresponds to this domain: 
  
  &lt;b&gt; {{email.email|domain}} &lt;/b&gt;
  &lt;/p&gt;
  
  {% endfor %}
  </code></pre>
  
  <p>It is currently making bold all domain names. What I want to do is to make bold ONLY those email addresses with a 'valid' email extension (for example, only those at the domain '@gmail.com'). How do I apply an if or ifequal statement to do this?</p>
  
  <p>For example, this is the logic I want it to have --</p>
  
  <pre><code>{% for email in user_list %}
  
  &lt;p&gt; 
  {{email.email}} corresponds to this domain: 
  
      {% if domain = 'specified extension' %}
      &lt;b&gt; {{email.email|domain}} &lt;/b&gt;
      {% else %}
      {{ email.email|domain }}
      {% endif %}
  
  &lt;/p&gt;
  
  {% endfor %}
  </code></pre>
  
  <p>Update:</p>
  
  <p>OK -- I got this working by creating a custom model in <code>models.py</code>, like so -- </p>
  
  <pre><code>class Table(models.Model):
      name = models.CharField(max_length=50)
      email = models.CharField(max_length=50)
      def valid_email(self):
          verified = ['yahoo.com','gmail.com']
          domain = self.email.split('@')[1]
          return domain in verified
  </code></pre>
  
  <p>And in the template <code>index.html</code> -- </p>
  
  <pre><code>{% for email in user_list %}
  
  &lt;p&gt; 
  {{email.email}} corresponds to this domain: 
  
      {% if email.valid_email %}
      &lt;b&gt;{{ email.email|domain}}&lt;/b&gt;
      {% else %}
      {{ email.email|domain}}
      {% endif %}
  &lt;/p&gt;
  
  {% endfor %}
  </code></pre>
  
  <p>This works well now, but my concern is that when I need to update the <code>models.py</code> and tamper with the verified email list. Where would be a better place to hold this <code>valid_emails()</code> function, such that I can update it easily? And then how would I reference the function in the template (if different than current)? Thank you.</p>