diff options
author | Karen Tracey <kmtracey@gmail.com> | 2010-12-22 03:34:04 +0000 |
---|---|---|
committer | Karen Tracey <kmtracey@gmail.com> | 2010-12-22 03:34:04 +0000 |
commit | b1f6a4d66fd7f987a41c1e1aaa43907d9d347ba6 (patch) | |
tree | bf6b4aa355633fbd97c55a1967b7169b8e764f42 /django/db/backends/postgresql/operations.py | |
parent | f0cd656ee085863d3a37f1bfb8351486428b4df2 (diff) | |
download | django-b1f6a4d66fd7f987a41c1e1aaa43907d9d347ba6.tar.gz |
Fixed #10154: Allow combining F expressions with timedelta values.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15018 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r-- | django/db/backends/postgresql/operations.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index e8ce3f242b..83fe7c21ec 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -27,6 +27,23 @@ class DatabaseOperations(BaseDatabaseOperations): else: return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name) + def date_interval_sql(self, sql, connector, timedelta): + """ + implements the interval functionality for expressions + format for Postgres: + (datefield + interval '3 days 200 seconds 5 microseconds') + """ + modifiers = [] + if timedelta.days: + modifiers.append(u'%s days' % timedelta.days) + if timedelta.seconds: + modifiers.append(u'%s seconds' % timedelta.seconds) + if timedelta.microseconds: + modifiers.append(u'%s microseconds' % timedelta.microseconds) + mods = u' '.join(modifiers) + conn = u' %s ' % connector + return u'(%s)' % conn.join([sql, u'interval \'%s\'' % mods]) + def date_trunc_sql(self, lookup_type, field_name): # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name) |