From 48f42dd34418526bda42a48f13ea382baa163ca3 Mon Sep 17 00:00:00 2001 From: mrampant Date: Thu, 24 Feb 2022 08:53:50 -0500 Subject: [PATCH] - using drf date field format to parse datetime/date/time when provided (over REST_FRAMEWORK global setting) - fixes #55 --- drf_excel/fields.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drf_excel/fields.py b/drf_excel/fields.py index 09c939c..8dfb293 100644 --- a/drf_excel/fields.py +++ b/drf_excel/fields.py @@ -110,8 +110,10 @@ def __init__(self, **kwargs): super().__init__(**kwargs) def _parse_date(self, value, setting_format, iso_parse_func): - # Parse format is DRF output format: DATETIME_FORMAT, DATE_FORMAT or TIME_FORMAT - parse_format = getattr(drf_settings, setting_format) + # Parse format is Field format if provided. + drf_format = getattr(self.drf_field, "format", None) + # Otherwise, use DRF output format: DATETIME_FORMAT, DATE_FORMAT or TIME_FORMAT + parse_format = drf_format or getattr(drf_settings, setting_format) # Use the provided iso parse function for the special case ISO_8601 if parse_format.lower() == ISO_8601: return iso_parse_func(value)