title: django queryset group by field
body: <h1> i have a listview and want to group by based on foreign key id </h1>
  
   views.py 
  
  <hr>
  
  <pre><code>class SelectListView(ListView):
      model=MyModel
      template_name = "/select_list.html"
      context_object_name = 'selectlist'
      queryset = MyModel.objects.all().values('ItemType_id')
  
      paginate_by = 10
  
      def get_context_data(self, **kwargs):
  
          context = super(SelectListView, self).get_context_data(**kwargs)
          context['range'] = range(context["paginator"].num_pages)
          return context
  </code></pre>
  
  <hr>
  
   models.py 
  
  <hr>
  
  <pre><code>class ItemType(models.Model):
         ItemType=models.CharField(unique=True,max_length=40)
  class MyModel(models.Model):
         Type=models.ForeignKey(ItemType)
         ItemName=models.CharField(unique=True,max_length=40)       
  </code></pre>
  
  <h1>Question: I would like to group by the queryset by ItemType_id in the MyModel </h1>
  
  <h2>Expectation: select * from  MyModel group by ItemType_id</h2>