Skip to content

Commit

Permalink
Fixed #1754, #2211, #2192 -- allow date filtering comparisons to use …
Browse files Browse the repository at this point in the history
…strings as

well as date objects. Fixed a couple of admin crashes as well.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Jun 28, 2006
1 parent d6c95e9 commit 414bc24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/db/models/fields/__init__.py
Expand Up @@ -411,7 +411,7 @@ def to_python(self, value):
def get_db_prep_lookup(self, lookup_type, value):
if lookup_type == 'range':
value = [str(v) for v in value]
elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte', 'ne'):
elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte', 'ne') and hasattr(value, 'strftime'):
value = value.strftime('%Y-%m-%d')
else:
value = str(value)
Expand Down
4 changes: 4 additions & 0 deletions tests/modeltests/lookup/models.py
Expand Up @@ -58,6 +58,10 @@ def __str__(self):
>>> Article.objects.filter(headline__startswith='Blah blah').count()
0L
# Date and date/time lookups can also be done with strings.
>>> Article.objects.filter(pub_date__exact='2005-07-27 00:00:00').count()
3L
# in_bulk() takes a list of IDs and returns a dictionary mapping IDs
# to objects.
>>> Article.objects.in_bulk([1, 2])
Expand Down

0 comments on commit 414bc24

Please sign in to comment.