From 42f4f44356044ee57b7efd32a423c01e2b9454bc Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Fri, 14 Sep 2007 16:48:47 +0000 Subject: [PATCH] Fixed #3146: DateFields no longer barf when confronted by strings. Thanks, Deepak Thukral. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6193 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/db/models/fields/__init__.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index cb69ebd0b0..1e56bd3412 100644 --- a/AUTHORS +++ b/AUTHORS @@ -278,6 +278,7 @@ answer newbie questions, and generally made Django that much better: Frank Tegtmeyer thebjorn Zach Thompson + Deepak Thukral tibimicu@gmax.net tobias@neuyork.de Tom Tobin diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 795f8936bd..3792a30a88 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -538,7 +538,12 @@ class DateField(Field): def get_db_prep_save(self, value): # Casts dates into string format for entry into database. if value is not None: - value = value.strftime('%Y-%m-%d') + try: + value = value.strftime('%Y-%m-%d') + except AttributeError: + # If value is already a string it won't have a strftime method, + # so we'll just let it pass through. + pass return Field.get_db_prep_save(self, value) def get_manipulator_field_objs(self):