title: Django querying on range of days with timezone.now and __range broken?
body: <p>I am running Django 1.4.3 and Python 2.7, with a PostgreSQL database (9.2.2). I have a model with a "last_view" field that is a timestamp of when a record is last viewed by a user. On my front page I want to display the ten most viewed items within the last week, so in my ListView I tried using this for my queryset:</p>
  
  <pre><code>startdate = timezone.now() - datetime.timedelta(days=7)
  enddate = timezone.now()
  urlpatterns = patterns('',
      url(r'^$',
          ListView.as_view(
              queryset=Tag.objects.filter(last_view__range=([startdate, enddate])).order_by('-views')[:10],
              context_object_name='most_viewed_list',
              template_name='tags/index.html'),
          name='index'),
  </code></pre>
  
  <p>This works when I first load the page. If I click any of the records and "view" them, the last_view attribute is updated in the database--but if I then reload the page, this item disappears from the "Recently Viewed" list (formed by the queryset described above).</p>
  
  <p>I thought the problem was related to this <a href="https://stackoverflow.com/questions/13225890/django-default-timezone-now-saves-records-using-old-time">post</a>, where it seems like the "enddate" of timezone.now() is limited by when I start my server process. So when I click on a link after the server is running, the "current time" is in the future compared to "now()" and outside of the range (that is why the record I click disappears on a page reload). However, if I change things to just <strong>now</strong> as in the post mentioned above, I get an error on page load:</p>
  
  <pre><code>startdate = timezone.now - datetime.timedelta(days=7)
  enddate = timezone.now
  </code></pre>
  
  <p>unsupported operand type(s) for -: 'function' and 'datetime.timedelta'</p>
  
  <p>So I cannot create my startdate variable. I can get this to work by changing my queryset from _range to _gte, but it seems like that will break over time if <strong>now()</strong> is really timestamped to when the server process starts instead of "current time." </p>
  
  <pre><code>queryset=Tag.objects.filter(last_view__gte=(timezone.now() - datetime.timedelta(days=7)).order_by('-views')[:10]
  </code></pre>
  
  <p>The <a href="https://docs.djangoproject.com/en/dev/intro/tutorial05/" rel="nofollow noreferrer">Django Tutorial on testing</a> does show the use of <strong>now</strong> in making queries over dates, however they do not show how to subtract days from <strong>now</strong> or use it with timedelta or a date range...</p>
  
  <p>Can someone please explain how to take a time difference from the actual, current time, i.e. using <strong>now</strong> instead of <strong>now()</strong>? I would also like to better understand the limitations of using <strong>now()</strong> versus <strong>now</strong>. I cannot find great documentation on this, since all examples I can find with timedelta() refer to timezone.now() or datetime.now(), which works (just not the way I want it to).</p>
  
  <p>Thanks!</p>