title: python django sort with lambda with if statement
body: <p>I have date and some dollar gross model:</p>
  
  <pre><code>class FirstDate(models.Model):
      gross = models.DecimalField(max_digits=12, decimal_places=2, default=0)
      updated = models.DateTimeField(auto_now=True)
  
  class SecondDate(models.Model):
      gross = models.DecimalField(max_digits=12, decimal_places=2, default=0)
      updated = models.DateTimeField(auto_now=True)
  </code></pre>
  
  <p>And want to sort it by <code>gross</code>, and if <code>gross</code> is the same, then sort it with <code>updated</code> field</p>
  
  <p>For example, </p>
  
  <pre><code>qs1 = SoloDate.objects.all()[:2]
  qs2 = GroupDate.objects.all()[:2]
  
  result_list = sorted(
      chain(qs1, qs2),
      key=lambda x: x.gross # and if gross is the same, for the gross same objects, x.updated and then update was also the same, x.pk,
      reverse=True
  )
  </code></pre>
  
  <p>I mean, let me say that there is two objects individually from qs1 and qs2.</p>
  
  <pre><code># objects from qs1
  qs1_obj1 = {
  'pk': 1,
  'gross': 5,
  'updated': 2018-11-24 10:53:23.360707+00:00
  }
  
  qs1_obj2 = {
  'pk': 2,
  'gross': 5,
  'updated': 2018-11-25 10:53:23.360707+00:00
  }
  
  # objects from qs2
  qs2_obj1 = {
  'pk': 3,
  'gross': 5,
  'updated': 2018-11-24 10:53:23.360707+00:00
  }
  
  qs2_obj2 = {
  'pk': 4,
  'gross': 1,
  'updated': 2018-11-23 10:53:23.360707+00:00
  }
  </code></pre>
  
  <p>It's <code>result_list</code> order will be <code>qs1_obj1</code>, <code>qs2_obj1</code>, <code>qs1_obj2</code>, <code>qs_2_obj_2</code>.</p>
  
  <p>Reasons is it: </p>
  
  <p><code>qs1_obj1</code>: 1.by gross, 2.by updated, 3.by pk, </p>
  
  <p><code>qs2_obj1</code>: 1.by gross, 2.by updated, 3. but pk was not good, </p>
  
  <p><code>qs1_obj2</code>: 1.by gross, 2.but by dpdated was late, </p>
  
  <p><code>qs2_obj2</code>: 1.gross was small.</p>
  
  <p>Maybe it is not good question or bothersome question, I need help.</p>
  
  <p>Question line is that : </p>
  
  <pre><code>key=lambda x: x.gross # and if gross is the same, for the same gross objects, x.updated and then update was also the same, x.pk,
  </code></pre>
  
  <p>How can I do this?</p>