Fixed #2471 -- Got date-based generic views working with SQLite DateFields. Thanks for the patch, Steven Armstrong

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3633 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-08-21 17:40:54 +00:00
parent 128151ebc8
commit ff5e01db5d
1 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,7 @@
from django.template import loader, RequestContext from django.template import loader, RequestContext
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.xheaders import populate_xheaders from django.core.xheaders import populate_xheaders
from django.db.models.fields import DateTimeField
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
import datetime, time import datetime, time
@ -235,9 +236,10 @@ def archive_day(request, year, month, day, queryset, date_field,
model = queryset.model model = queryset.model
now = datetime.datetime.now() now = datetime.datetime.now()
lookup_kwargs = { if isinstance(model._meta.get_field(date_field), DateTimeField):
'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)), lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))}
} else:
lookup_kwargs = {date_field: date}
# Only bother to check current date if the date isn't in the past and future objects aren't requested. # Only bother to check current date if the date isn't in the past and future objects aren't requested.
if date >= now.date() and not allow_future: if date >= now.date() and not allow_future:
@ -304,9 +306,10 @@ def object_detail(request, year, month, day, queryset, date_field,
model = queryset.model model = queryset.model
now = datetime.datetime.now() now = datetime.datetime.now()
lookup_kwargs = { if isinstance(model._meta.get_field(date_field), DateTimeField):
'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)), lookup_kwargs = {'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))}
} else:
lookup_kwargs = {date_field: date}
# Only bother to check current date if the date isn't in the past and future objects aren't requested. # Only bother to check current date if the date isn't in the past and future objects aren't requested.
if date >= now.date() and not allow_future: if date >= now.date() and not allow_future: