title: Custom manager - querying on abstract base class
body: <p>I've written an abstract base class which groups together common fields for some of my tables.  I would like to be able to query all of those fields in the same way, using a manager.</p>
  
  <pre><code>class TemporalModel(models.Model):
      objects = models.Manager()
      today = TodayManager()
  
      time = models.DateTimeField()
  
      class Meta:
          abstract = True
          get_latest_by = 'time'
  </code></pre>
  
  <p>One simple example of this, as shown above, is to be able to query subclasses of TemporalModel (which all have a 'time' field) for the entries today.</p>
  
  <p>I thus wrote a manager:</p>
  
  <pre><code>class TodayManager(models.Manager):
      def get_query_set(self):
          now = timezone.now()
          today = datetime(now.year, now.month, now.day, tzinfo=now.tzinfo)
          tomorrow = today + timedelta(days=1)
  
          qs = models.Manager.get_query_set(self).filter(time &gt;= today)
          qs = qs.filter(time &lt; tomorrow)
  
          return qs
  </code></pre>
  
  <p>Attempting to use this fails with a NameError (time not defined).  I presume that this is for the same reason as in <a href="https://stackoverflow.com/questions/7549898/django-custom-model-manager-queries-in-abstract-classes">this question</a> - the field is not on the abstract class, but rather on the subclass.</p>
  
  <p>However, I'm never actually calling this on the abstract class.  If I have something like the following:</p>
  
  <pre><code>class SomeTemporalThing(TemporalModel):
      pass # I'm a real table! :)
  </code></pre>
  
  <p>then I want to be able to call, eg, SomeTemporalThing.today.all(), and have django perform the time >= today / time &lt; tomorrow lookups on the child table.</p>
  
  <p>Is it possible to achieve this without moving the manager definition to the child class (which would result in repetition)?  </p>
  
  <p>My reading of the <a href="https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers-and-model-inheritance" rel="nofollow noreferrer">custom manager documentation</a> suggests that it should be possible, but I'm stumped as to how.</p>