title: Django query by separate date and time fields (how to perform conditional order_by)
body: <p>I have a <code>Meeting</code> model. It has a separate date and time field, the reason why it is not a single datetime field is that the time is allowed to be null.
  If I used a single <code>datetime</code> field and set the hours/minutes to <code>00:00</code> if no time is given, then I can't distinguish that from a meeting set at <code>00:00</code>. And some unusual sentinel value like <code>13:37:42</code> as no meeting is a weird hack.</p>
  <p>Here's the model:</p>
  <pre><code>class Meeting(models.Model):
      meeting_date = models.DateField(db_index=True)
      meeting_time = models.TimeField(db_index=True, null=True, blank=True)
  </code></pre>
  <p>Now the problem comes in to filter by a given date/time.</p>
  <p>So I think the solution is to filter by date, then order by the time. E.g. to get the latest meeting that is before now:</p>
  <pre><code>from datetime import datetime
  
  now = datetime.now()
  prev_meeting = (
      Meeting.objects.filter(meeting_date__lte=now.date())
      .order_by('-meeting_date', f'meeting_time &lt;= {now.time()}', '-meeting_time')
      .first()
  )
  </code></pre>
  <p>The <code> f'meeting_time &lt;= {now.time()}'</code> is the part I don't know how to do with the django ORM, but I know how to do with SQL. the <a href="https://docs.djangoproject.com/en/4.1/ref/models/querysets/#order-by" rel="nofollow noreferrer">Django Docs</a> do not mention conditional ordering.</p>