Ticket #5223: sqlite_year.diff

File sqlite_year.diff, 1.3 KB (added by raminf, 17 years ago)

I started working on this during the sprint and was trying to be more conservative to avoid problems with other backends. Thought I'd go ahead and toss it in as an alternative.

  • django/db/models/fields/__init__.py

     
    1313from django.core import validators
    1414from django import oldforms
    1515from django import newforms as forms
    16 from django.core.exceptions import ObjectDoesNotExist
     16from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
    1717from django.utils.functional import curry
    1818from django.utils.itercompat import tee
    1919from django.utils.text import capfirst
     
    226226                value = int(value)
    227227            except ValueError:
    228228                raise ValueError("The __year lookup type requires an integer argument")
    229             return ['%s-01-01 00:00:00' % value, '%s-12-31 23:59:59.999999' % value]
     229            try:
     230                if settings.DATABASE_ENGINE == "sqlite3":
     231                    date_start_format = '%s-01-01'
     232                else:
     233                    date_start_format = '%s-01-01 00:00:00'
     234            except:
     235                raise ImproperlyConfigured, "DATABASE_ENGINE not defined in settings.py"
     236            return [date_start_format % value, '%s-12-31 23:59:59.999999' % value]
    230237        raise TypeError("Field has invalid lookup: %s" % lookup_type)
    231238
    232239    def has_default(self):
Back to Top