Opened 13 years ago
Closed 12 years ago
#16443 closed Bug (fixed)
previous_day from views.generic.dates.DayArchiveView doesn't return the previous day
Reported by: | Bernhard Essl | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The previous_day from views.generic.dates.DayArchiveView returns not the previous day instead the day before the previous day (24 June -> 22 June).
# blog/models.py from django.db import models class Post(models.Model): title = models.TextField() pub_date = models.DateTimeField() def __unicode__(self): return u"%s" % (self.pub_date,) # url.py from django.conf.urls.defaults import patterns, include, url from django.views.generic import dates from django.views import generic from blog.models import Post class PostDayArchive(generic.DayArchiveView): queryset = Post.objects.all() date_field = 'pub_date' urlpatterns = patterns('', url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{1,2})/$', PostDayArchive.as_view()), ) # templates/blog/post_archive_day.html {{ previous_day }} # 4 objects post from june 21-24 Post.objects.all() [<Post: 2011-06-24 12:33:10>, <Post: 2011-06-23 13:33:10>, <Post: 2011-06-22 13:33:10>, <Post: 2011-06-21 13:33:10>] # page request $ curl http://127.0.0.1:8000/2011/jun/24/ June 22, 2011
When I open the page with the URL /2011/jun/24/ I get "June 22, 2011" for the "previous_day"; on /2011/jun/23/ I get "June 21, 2011" and on /2011/jun/22/ I get None.
Some notes:
- On production sometimes previous_day is working correctly. Didn't find a pattern. :(
- I use Django trunk (16527)
- The code works fine with models.DateField() instead of models.DateTimeField()
- I tested with MySQL and SQLite
- all other template tags like next_day or today are working
Change History (4)
comment:2 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 13 years ago
This problem is probably fixed since this commit, where the implementation of date filters was largely rewritten.
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Please re-open if you can reproduce the issue with Django 1.5
I traced down the problem a bit https://code.djangoproject.com/browser/django/trunk/django/views/generic/dates.py#L560.
For the date 2011-06-24; naive_result (a datetime value of the previos day) is 2011-06-23 and the raw SQL query looks like this:
I think it would be better to ask for <= '2011-06-24 00:00' in this case to return all records from the previous day and sure it's not a problem with DateFields.