title: Creating histograms from ManyToMany tables
body: <pre><code>class Author(models.Model):
      name = models.CharField(max_length=100)
  
  class Book(models.Model):
      isbn = models.CharField(max_length=9)
      name = models.CharField(max_length=300)
      authors = models.ManyToManyField(Author, through='BookAuthor')
  
  class BookAuthor(models.Model):
      book = models.ForeignKey('Book', on_delete=models.CASCADE)
      author = models.ForeignKey('Author', on_delete=models.CASCADE)
      position = models.IntegerField()
  </code></pre>
  
  <p>In the model above, I'm recording the position that the name of an author
  has for a given book (see <code>position</code> field in <code>BookAuthor</code>table), i.e. imagine "Paulo Coelho" is "first author" on Book X, and "second author" on book Y, and "third author" on book Z.</p>
  
  <p>For each author, I would like to create a histogram, in which each
  histogram bin counts how many times the name of the author appeared on the "ith" position across all books. For instance:</p>
  
  <pre><code>AuthorName, No1stAuth, No2ndAuth, No3rdAuth
  --------------------------------------------
  Paulo Coelho, 3, 1, 1
  Mario Vargas Llosa, 4, 2, 0
  </code></pre>
  
  <p>Which means Paulo Coelho appears 3x as first author, 1x as second author, and 1x as third author.
  Mario Vargas Llosa appears 4x as first author, 2x as second author, and 0x as third author. You can assume, that each book has at maximum 5 authors.</p>