Skip to content

Commit 77852c9

Browse files
authored
Merge pull request #56 from wharton/fix_drf_datefield_format
Take DRF date field format over global REST_FRAMEWORK when provided
2 parents b18d12c + 48f42dd commit 77852c9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drf_excel/fields.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ def __init__(self, **kwargs):
110110
super().__init__(**kwargs)
111111

112112
def _parse_date(self, value, setting_format, iso_parse_func):
113-
# Parse format is DRF output format: DATETIME_FORMAT, DATE_FORMAT or TIME_FORMAT
114-
parse_format = getattr(drf_settings, setting_format)
113+
# Parse format is Field format if provided.
114+
drf_format = getattr(self.drf_field, "format", None)
115+
# Otherwise, use DRF output format: DATETIME_FORMAT, DATE_FORMAT or TIME_FORMAT
116+
parse_format = drf_format or getattr(drf_settings, setting_format)
115117
# Use the provided iso parse function for the special case ISO_8601
116118
if parse_format.lower() == ISO_8601:
117119
return iso_parse_func(value)

0 commit comments

Comments
 (0)