title: Django REST Framework, ordering m2m serialization via a through table
body: <p>I am trying to produce JSON using Django REST Framework (3.3.1), which should order a m2m field using a through model. This works in normal django views - the ordering is honoured (ie in the admin lists). However, using a standard DRF set of ModelSerializers, the through table specified on the django models is not used for the ordering of the returned m2m set. </p>
  
  <p>Is there an easy way to achieve the ordering that i'm after? Or do i need to generate the data and return in my own DRF responses?</p>
  
  <p>I have the following models:</p>
  
  <pre><code>class Pitch(models.Model):
      """ A pitch like 'A4" (A at octave 4) with midi note - ie 60 = middle C (C3) """
      name = models.CharField(max_length=5)
      midi_note = models.IntegerField()
  
      def __unicode__(self):
          return self.name
  
      class Meta:
          ordering = ['midi_note']
          verbose_name_plural = 'pitches'
  
  
  class Pattern(models.Model):
      """ ie A Major """
      name = models.CharField(max_length=50, default="")
      pitches = models.ManyToManyField(Pitch, through='PitchPosition')
  
      def __unicode__(self):
          return u"{0}".format(self.name)
  
  
  class PitchPosition(models.Model):
      """
      The through table for a pitch in a pattern, needed as 
      scales/arpeggios go up and down, so pitches appear 
      twice in the list
  
      """
      pattern = models.ForeignKey(Pattern)
      pitch = models.ForeignKey(Pitch)
      order = models.IntegerField(default=0)
  
      def __unicode__(self):
          return u"{0} ({1})".format(self.pitch, self.pattern)
  
      class Meta:
          ordering = ['pattern', 'order']
  </code></pre>
  
  <p>Serializing the data with DRF, the through table ordering is not being honoured:</p>
  
  <pre><code>class PitchSerializer(serializers.ModelSerializer):
      class Meta:
          model = Pitch
          fields = ('name', 'midi_note')
  
  
  class PatternSerializer(serializers.ModelSerializer):
      name = serializers.CharField()
      pitches = PitchSerializer(many=True)
  
      class Meta:
          model = Pattern
          fields = ('name', 'pitches')
  </code></pre>
  
  <p>Produces:</p>
  
  <pre><code>[
      {
          "name": "D Major",
          "pitches": [
              {
                  "name": "D4",
                  "midi_note": 62
              },
              {
                  "name": "D4",
                  "midi_note": 62
              },
              {
                  "name": "E4",
                  "midi_note": 64
              },
              {
                  "name": "E4",
                  "midi_note": 64
              },
              {
                  "name": "F#4",
                  "midi_note": 66
              },
              {
                  "name": "F#4",
                  "midi_note": 66
              },
              {
                  "name": "G4",
                  "midi_note": 67
              },
              {
                  "name": "G4",
                  "midi_note": 67
              },
              {
                  "name": "A4",
                  "midi_note": 69
              },
              {
                  "name": "A4",
                  "midi_note": 69
              },
              {
                  "name": "B4",
                  "midi_note": 71
              },
              {
                  "name": "B4",
                  "midi_note": 71
              },
              {
                  "name": "C#5",
                  "midi_note": 73
              },
              {
                  "name": "C#5",
                  "midi_note": 73
              },
              {
                  "name": "D5",
                  "midi_note": 74
              }
          ]
      }
  ]
  </code></pre>