summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/operations.py
diff options
context:
space:
mode:
authorSigurd Ljødal <sigurd@ljodal.no>2017-09-28 22:28:48 +0200
committerTim Graham <timograham@gmail.com>2018-08-18 13:09:15 -0400
commit3e09b37f80ab34cf57e245e1fcdabb3d4ff92a38 (patch)
tree7b56c5caeb4d6ebe6b5075c711c36a0572419c6f /django/db/backends/mysql/operations.py
parentc832885a3e8659d4a704bf103d523b610c24e4ec (diff)
downloaddjango-3e09b37f80ab34cf57e245e1fcdabb3d4ff92a38.tar.gz
Fixed #28649 -- Added ExtractIsoYear database function and iso_year lookup.
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r--django/db/backends/mysql/operations.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index babf522e45..877c32b6a7 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -42,6 +42,10 @@ class DatabaseOperations(BaseDatabaseOperations):
# other database backends.
# Mode 3: Monday, 1-53, with 4 or more days this year.
return "WEEK(%s, 3)" % field_name
+ elif lookup_type == 'iso_year':
+ # Get the year part from the YEARWEEK function, which returns a
+ # number as year * 100 + week.
+ return "TRUNCATE(YEARWEEK(%s, 3), -2) / 100" % field_name
else:
# EXTRACT returns 1-53 based on ISO-8601 for the week number.
return "EXTRACT(%s FROM %s)" % (lookup_type.upper(), field_name)