Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1754, #2211, #2192 -- allow date filtering comparisons to use …

…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...
commit 414bc24e81014239cc71f0b04e85622050068e9d 1 parent d6c95e9
Malcolm Tredinnick authored June 28, 2006
2  django/db/models/fields/__init__.py
@@ -411,7 +411,7 @@ def to_python(self, value):
411 411
     def get_db_prep_lookup(self, lookup_type, value):
412 412
         if lookup_type == 'range':
413 413
             value = [str(v) for v in value]
414  
-        elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte', 'ne'):
  414
+        elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte', 'ne') and hasattr(value, 'strftime'):
415 415
             value = value.strftime('%Y-%m-%d')
416 416
         else:
417 417
             value = str(value)
4  tests/modeltests/lookup/models.py
@@ -58,6 +58,10 @@ def __str__(self):
58 58
 >>> Article.objects.filter(headline__startswith='Blah blah').count()
59 59
 0L
60 60
 
  61
+# Date and date/time lookups can also be done with strings.
  62
+>>> Article.objects.filter(pub_date__exact='2005-07-27 00:00:00').count()
  63
+3L
  64
+
61 65
 # in_bulk() takes a list of IDs and returns a dictionary mapping IDs
62 66
 # to objects.
63 67
 >>> Article.objects.in_bulk([1, 2])

0 notes on commit 414bc24

Please sign in to comment.
Something went wrong with that request. Please try again.