|
8 | 8 | import warnings
|
9 | 9 |
|
10 | 10 | # Django
|
| 11 | +import django |
11 | 12 | from django.core import checks
|
12 | 13 | from django.core.exceptions import ValidationError
|
13 | 14 | from django.db.models.fields import DateTimeField, CharField
|
@@ -83,15 +84,26 @@ def get_prep_value(self, value):
|
83 | 84 |
|
84 | 85 | return value
|
85 | 86 |
|
86 |
| - def from_db_value(self, value, expression, connection, context): # noqa |
87 |
| - """ |
88 |
| - Converts a value as returned by the database to a Python object. It is |
89 |
| - the reverse of get_prep_value(). - New in Django 1.8 |
90 |
| - """ |
91 |
| - if value: |
92 |
| - value = self.to_python(value) |
93 |
| - |
94 |
| - return value |
| 87 | + # Django 2.0 updates the signature of from_db_value. |
| 88 | + # https://docs.djangoproject.com/en/2.0/releases/2.0/#context-argument-of-field-from-db-value-and-expression-convert-value |
| 89 | + if django.VERSION < (2,): |
| 90 | + def from_db_value(self, value, expression, connection, context): # noqa |
| 91 | + """ |
| 92 | + Converts a value as returned by the database to a Python object. It is |
| 93 | + the reverse of get_prep_value(). - New in Django 1.8 |
| 94 | + """ |
| 95 | + if value: |
| 96 | + value = self.to_python(value) |
| 97 | + return value |
| 98 | + else: |
| 99 | + def from_db_value(self, value, expression, connection): |
| 100 | + """ |
| 101 | + Converts a value as returned by the database to a Python object. It is |
| 102 | + the reverse of get_prep_value(). - New in Django 1.8 |
| 103 | + """ |
| 104 | + if value: |
| 105 | + value = self.to_python(value) |
| 106 | + return value |
95 | 107 |
|
96 | 108 | def to_python(self, value):
|
97 | 109 | """Returns a datetime.tzinfo instance for the value."""
|
|
0 commit comments