title: Iterate through groups, then loop item by item
body: <p><strong>Django 1.11.4</strong></p>
  
  <p><strong>PostgreSQL 9.6.3</strong></p>
  
  <p>Below is a bookmark model.</p>
  
  <pre><code>class Bookmark(CommonUrlMethodsMixin,
                 models.Model):
      memo = models.CharField(max_length=200,
                              null=False,
                              blank=True,
                              default="")  # Intentionally blank.
                                                # For displaying in ModelForm.
  
      content_type = models.ForeignKey(ContentType)
      content_type_for_filter = models.CharField(max_length=6,
                              null=False,
                              blank=True,
                              default="")
      object_id = models.PositiveIntegerField()
      content_object = GenericForeignKey('content_type', 'object_id')
      user = models.ForeignKey(User,
                               on_delete=models.CASCADE)
  
      def __str__(self):
          return "{}: {} {}".format(self.content_object._meta.verbose_name.title(), self.content_object, self.memo)
  
      class Meta:
          verbose_name = _("bookmark")
  </code></pre>
  
  <p>In my project bookmarked can be a Frame, an Item, a Sheet.
  So, I organized a special field in the Bookmark model content_type_for_filter. It may contain either "frame", or "item" or "sheet". </p>
  
  <p>Bookmarks must be shown in groups: first bookmarks for Frames, then for Items and lastly for Sheets:</p>
  
  <pre><code>Frames
       bookmark 1
       bookmark 2
       bookmark 3
  Sheets
       bookmark 4
       bookmark 5
  Items
       bookmark 6
       bookmark 7
       bookmark 8
  </code></pre>
  
  <p>Then in the personal area I'd like to show the bookmarks. In views now I have:</p>
  
  <pre><code>def get_context_data(self, **kwargs):
      bookmarks = user.bookmark_set.all()
      # context['bookmarks'] = bookmarks
  </code></pre>
  
  <p>It seems that my code is not acceptable. Look: I will have to handle bookmarks somehow in Python. Use a named tuple or something. Or at least three lists of lists. </p>
  
  <p>I suppose, that my select from the data base is not optimal. Is suppose, it  may be possible to group by "content_type_for_filter". 
  Then loop through groups. And then loop through the contents of the groups. But I don't know how.</p>
  
  <p>Could you help me understand how to do that? Is it possible with ORM? If not, how to do that without ORM?</p>