title: django comparing datetime.time from Time fields - Type Error
body: <p>I am trying to compare two datetime.time variables in some python code in a View.</p>
  
  <p>p_obj.time_start is a Time field</p>
  
  <p>b_obj.time_start is also a Time field</p>
  
  <pre><code>slot_start = p_obj.time_start
  whereami = slot_start
  ...
  for b_obj in mydata:
     while (b_obj.time_start &gt; whereami):
     ...
  ...
  </code></pre>
  
  <p>When I run the view, I get a Type Error
  can't compare datetime.time to builtin_function_or_method</p>
  
  <p>Looking at the django debug I can see that:</p>
  
  <pre><code>whereami    is &lt;built-in method time of datetime.datetime object at 0x7fdb1136ee40&gt;
  </code></pre>
  
  <p>but</p>
  
  <pre><code>slot_start  is  datetime.time(10, 0)
  </code></pre>
  
  <p>I believe my problem is due to the way the comparision is evaluating.</p>
  
  <p>I have tried various permutations, and while I can get both variables independently to resolve to a datetime.time (like slot_start is) I can't see to get them both to  do it prior to or during the while comparison. Is there a way to force the evaluation prior to the comparison? </p>
  
  <p>I have a thought that this might be something to do with the first method being evaluated then the result (a datetime.time) not being comparable to the second method (which is a method). Is there some simple syntax I am missing to make both elements evaluate prior to the comparison?</p>
  
  <p>Strangely </p>
  
  <pre><code>if  (whereami &lt; b_obj.time_start):
  </code></pre>
  
  <p>doesn't throw any error, and does appear to work correctly (in that it performs the expected comparisons).</p>
  
  <p>Adding more info as requested:</p>
  
  <pre><code>class Booking(models.Model):
      ....
      practavail = models.ForeignKey(PractAvail, on_delete=models.PROTECT, blank=False)
      time_start = models.TimeField("Start Time", blank=False)
      time_finish = models.TimeField("Finish Time", blank=False)
      ....
  
  class PractAvail(models.Model):
      ....
      time_start = models.TimeField("Start Time", blank=False)
      time_finish = models.TimeField("Finish Time", blank=False)
      ....
  </code></pre>
  
  <p>Then in my view (skipping non essential bits):</p>
  
  <pre><code>p_avails = PractAvail.objects.filter(date=inputdate).order_by('time_start')
  for p_obj in p_avails:
      mydata['bookings'][p_obj.pk] =  p_obj.booking_set.all().order_by('time_start')
  
      for b_obj in mydata['bookings'][p_obj.pk]:
  </code></pre>
  
  <p>and then the while loop as above.</p>
  
  <p>I have also found that my code works fine with:</p>
  
  <pre><code>           if (b_obj.time_start &gt; whereami):
                 yesdoloop = True
             else:
                 yesdoloop = False
             while yesdoloop:
                ...do stuff, including updating whereami...
                if (b_obj.time_start &gt; whereami):
                      yesdoloop = True
                else:
                      yesdoloop = False
  </code></pre>
  
  <p>So, there is definitely something different about how a while compares as against how an if compares (I think?!)</p>