title: Improving an existing badge system for a Django web forum
body: <p>I have a Django forum where users post comments and interact with one another. Everyone has a nickname, and can write 250 characters per comment. There's also an upvote/downvote functionality to regulate the quality of comments.</p>
  
  <p>Moreover, some *verified *users get badges. There's just one type of badge currently, and is given out to users with a certain real-life skill (we verify that via a background check).</p>
  
  <p>Each badge shows up as nothing but a * next to a verified person's nickname. E.g.:</p>
  
  <blockquote>
    <p>mhb11: Have you checked out the reviews to the upcoming Civil War
    movie? Here: [link]</p>
    
    <p>Swindon-411*: I bet BvS > MCW :-D</p>
    
    <p>samantha1: oh boy!</p>
  </blockquote>
  
  <p><strong>Swindon-411*</strong> above is one of those verified users. I list all verified nicknames in <strong>nicknames.py</strong>, and then export the list to <strong>views.py</strong>. Then in every Django template of the project, I do:</p>
  
  <pre><code>{% for person in verified %}
        {% if person == comment.submitter.username %}
              &lt;span style="color:orange;"&gt;&lt;b&gt;*&lt;/b&gt;&lt;/span&gt;
        {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>Most of my templates contain this logic (which templates aren't supposed to). The project was small, so this approached worked prototypically. Now our users have scaled, and we're adding more badges too. I want to refactor the way I've implemented this. </p>
  
  <p>What's the least performance intensive, scalable way to accomplish this in my Django web app? Should I have a middleware, that reads every request and concatenates a badge next to a nickname? Should I move it as a property to the DB? Each <code>User</code> in my app is from <code>django.contrib.auth.models</code>. </p>
  
  <p>The best answer for me is one which outlines how you would do it, alongwith an illustrative example. I'm using Django &lt; 1.8, and my backend is PostgreSQL. Thanks in advance. This project has taught me much, and learning continues here.</p>