title: How to check if a user has permission when looping through all permissions?
body: <p>I have a model named Account, which is connected to the default User model. As of now, I'm looping through all permissions associated with the Account model, but I also want to check if the Account profile page's user has the one or more of the specific permissions that's being looped through. The purpose is just to create an easy overview.</p>
  
  <p>I have also tried checking <code>perms.cms.get_permission_codename</code>.</p>
  
  <h1>models.py</h1>
  
  <pre><code>class Account(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      site = models.CharField(max_length=50, choices=(('all', 'all'), ('danielk', 'danielk'), ('flis', 'flis'), ('vmusic', 'vmusic')), blank=True)
      site_role = models.CharField(max_length=50, choices=(('Administrator', 'Administrator'), ('Moderator', 'Moderator'), ('Editor', 'Editor')))
      phone_number = models.CharField(max_length=8)
      birth_date = models.DateField()
      street_adress = models.CharField(max_length=255)
      note = models.TextField(blank=True);
      zip_code = models.CharField(max_length=4)
      city = models.CharField(max_length=255)
  
      def formatedPhone(self, country=None):
          return phonenumbers.parse(Account.phone_number, "NO")
  
      """
      def __str__(self):
          return "%s %s" % (self.User.first_name, self.user.last_name)
      """
  
      def get_absolute_url(self):
          return reverse('account-detail', kwargs={'pk': self.pk})
  
      class Meta:
          verbose_name = 'Account meta'
          verbose_name_plural = 'Accounts meta'
          permissions = (
              ("has_user_hijack_permission", "Allows the user to log in as others"),
              ("has_user_management", "Allows a user to deactivate/delete other users"),
              ("has_user_site_edit", "Allows a user to edit site and role details"),
              ("has_user_takeout", "Can export user details"),
          )
  </code></pre>
  
  <h1>views.py</h1>
  
  <pre><code>class cms_users_user_permissions(generic.DetailView):
      model = Account
      template_name = 'cms/users/cms-users-user-permissions.html'
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          context["permissions"] = Permission.objects.filter(content_type=ContentType.objects.get_for_model(Account))
          #context['permissions'] = Permission.objects.filter(content_type_id=7)
          return context
  </code></pre>
  
  <h1>table.html</h1>
  
  <pre><code>&lt;table class="table is-fullwidth"&gt;
      &lt;tbody&gt;
          {% for permission in permissions %}
              &lt;tr&gt;
                  &lt;td style="width: 300px;"&gt;{{ permission.codename }}&lt;/td&gt;
                   &lt;td&gt;{{ permission.name }}&lt;/td&gt;
  
                   {% if account.user.has_perm %}
                       &lt;td&gt;
                           &lt;span class="icon is-small"&gt;
                               &lt;i class="fas fa-check-circle has-text-success"&gt;&lt;/i&gt;
                           &lt;/span&gt;
                       &lt;/td&gt;
                    {% else %}
                        &lt;td&gt;
                            &lt;span class="icon is-small"&gt;
                                &lt;i class="fas fa-times-circle has-text-danger"&gt;&lt;/i&gt;
                            &lt;/span&gt;
                         &lt;/td&gt;
                     {% endif %}
               &lt;/tr&gt;
            {% endfor %}      
         &lt;/tbody&gt;
     &lt;/table&gt;
  </code></pre>