Ticket #2471: date-based-generic-view_date-field.diff

File date-based-generic-view_date-field.diff, 1.7 KB (added by Steven Armstrong, 18 years ago)
  • django/django/views/generic/date_based.py

     
    235235    model = queryset.model
    236236    now = datetime.datetime.now()
    237237
    238     lookup_kwargs = {
    239         '%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
    240     }
     238    lookup_kwargs = {}
     239    from django.db.models.fields import DateTimeField
     240    if isinstance(model._meta.get_field(date_field), DateTimeField):
     241        lookup_kwargs['%s__range' % date_field] = (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
     242    else:
     243        lookup_kwargs[date_field] = date
    241244
    242245    # Only bother to check current date if the date isn't in the past and future objects aren't requested.
    243246    if date >= now.date() and not allow_future:
     
    304307    model = queryset.model
    305308    now = datetime.datetime.now()
    306309
    307     lookup_kwargs = {
    308         '%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
    309     }
     310    lookup_kwargs = {}
     311    from django.db.models.fields import DateTimeField
     312    if isinstance(model._meta.get_field(date_field), DateTimeField):
     313        lookup_kwargs['%s__range' % date_field] = (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
     314    else:
     315        lookup_kwargs[date_field] = date
    310316
    311317    # Only bother to check current date if the date isn't in the past and future objects aren't requested.
    312318    if date >= now.date() and not allow_future:
Back to Top