title: Passing group name of a user in context and accessing in template in django
body: <p>I have used mixins with class-based views in my django app. I also have created a group named Instructors to allow only user belonging to this group to have certain permissions which are to edit, add and delete a course object.
  In the <strong><em>ManageCourseList View</em></strong> which is responsible for rendering the courses created by the current user, I tried to override the <strong><em>get_context_data</em></strong> method to pass an additional <em>'group_list'</em> argument which contains the groups the user belongs to.
  I tried to access it in the template ManageCourseList view renders.
  The problem is though the current user belongs to Instructors group but still it renders the else condition data.
  Please help,My files:</p>
  
  <p>Views.py</p>
  
  <pre><code>from django.shortcuts import render
  from django.core.urlresolvers import reverse_lazy
  from django.views.generic.list import ListView
  from django.views.generic.edit import CreateView,UpdateView,DeleteView
  from django.contrib.auth.mixins import LoginRequiredMixin,PermissionRequiredMixin
  
  from .models import Course
  
  
  class OwnerMixin(object):
      def get_queryset(self):
          qs = super(OwnerMixin,self).get_queryset()
  
          return qs.filter(owner=self.request.user)
  
  class OwnerEditMixin(object):
      def form_valid(self,form):
          form.instance.owner = self.request.user
          return super(OwnerEditMixin, self).form_valid(form)
  
  class OwnerCourseMixin(OwnerMixin,LoginRequiredMixin):
      model = Course
      fields = ['subject','title','slug','overview'] # why use this attribute?
      success_url = reverse_lazy('courses:manage_course_list') # use of it?
  
  class OwnerCourseEditMixin(OwnerCourseMixin,OwnerEditMixin):
      fields = ['subject','title','slug','overview']
      success_url = reverse_lazy('courses:manage_course_list')
      template_name = 'courses/manage/course/form.html'
  
  class ManageCourseListView(OwnerCourseMixin,ListView):
      template_name = 'courses/manage/course/list.html'
  
      def get_context_data(self, **kwargs):
          context = super(ManageCourseListView,self).get_context_data(**kwargs)
          context['group_list'] = self.request.user.groups.all()
          return context
  </code></pre>
  
  <p>list.html</p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block title %}My courses{% endblock %}
  
  {% block content %}
      {% if group_list.0 == "Instructors" %}
      &lt;h1&gt;My courses&lt;/h1&gt;
          &lt;div class="module"&gt;
              {% for course in object_list %}
                  &lt;div class="course-info"&gt;
                      &lt;h3&gt;{{ course.title }}&lt;/h3&gt;
                      &lt;p&gt;
                          &lt;a href="{% url 'courses:course_edit' course.id %}"&gt;Edit&lt;/a&gt;
                          &lt;a href="{% url 'courses:course_delete' course.id %}"&gt;Delete&lt;/a&gt;
                      &lt;/p&gt;
                  &lt;/div&gt;
              {% empty %}
                  &lt;p&gt;You haven't created any courses yet.&lt;/p&gt;
              {% endfor %}
              &lt;p&gt;
                  &lt;a href="{% url 'courses:course_create' %}" class="button"&gt;Create new course&lt;/a&gt;
              &lt;/p&gt;
          &lt;/div&gt;
  
      {% else %}
      &lt;h1&gt;No courses to display&lt;/h1&gt;
      {% endif %}
  
  {% endblock %}
  </code></pre>