Skip to content

Commit

Permalink
Merge pull request #56 from wharton/fix_drf_datefield_format
Browse files Browse the repository at this point in the history
Take DRF date field format over global REST_FRAMEWORK when provided
  • Loading branch information
FlipperPA committed Feb 24, 2022
2 parents b18d12c + 48f42dd commit 77852c9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drf_excel/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 77852c9

Please sign in to comment.