title: Django - sort a formset before processing it?
body: <p>I have the following models in an app.</p>
  
  <p>Lesson
  Student
  Evaluation
  Parent</p>
  
  <p>Lesson and Student have a m2m relationship through Evaluation.</p>
  
  <p>I have an inline formset which allows me to create evaluation records at the same time I create a new lesson.</p>
  
  <p>I would like to sort the formset before I process it so that I can put all the records that share a common parent record together and carry out some additional tasks when saving the records.</p>
  
  <p>Here's a simplified example:</p>
  
  <pre><code>EvaluationFormset = inlineformset_factory(Lesson, Evaluation, extra=1, max_num=10)
  
  
  if request.method == 'POST': 
      form = LessonForm(request.POST, instance=lesson, user=request.user)
      formset = EvaluationFormset(request.POST, instance=lesson)
  
      if form.is_valid() and formset.is_valid():
          lesson = form.save()
          models = formset.save(commit=False)
  
          #Before I do this, I need to sort the formset based on evaluation.student.parent.
          #In the loop, I will perform an additional the first record for each parent
  
          for i in models:
              i.user = request.user
              i.lesson = lesson
              i.save()
  </code></pre>
  
  <p>Is there any easy way to this in Django?</p>
  
  <p>Any advice appreciated.</p>
  
  <p>Thanks.</p>