You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Allow format duration as ISO-8601
* Update tests/test_fields.py
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
* Update tests/test_fields.py
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
* Add validation for DurationField format, add more tests for it and improve related docs
* Add more precise validation check for duration field format and adjust docs
* Adjust typo in duration field docs
---------
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com>
*`format` - A string representing the output format. If not specified, this defaults to the same value as the `DURATION_FORMAT` settings key, which will be `'django'` unless set. Formats are described below. Setting this value to `None` indicates that Python `timedelta` objects should be returned by `to_representation`. In this case the date encoding will be determined by the renderer.
384
384
*`max_value` Validate that the duration provided is no greater than this value.
385
385
*`min_value` Validate that the duration provided is no less than this value.
386
386
387
+
#### `DurationField` formats
388
+
Format may either be the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style intervals should be used (eg `'P4DT1H15M20S'`), or `'django'` which indicates that Django interval format `'[DD] [HH:[MM:]]ss[.uuuuuu]'` should be used (eg: `'4 1:15:20'`).
Copy file name to clipboardExpand all lines: docs/api-guide/settings.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,6 +314,15 @@ May be a list including the string `'iso-8601'` or Python [strftime format][strf
314
314
315
315
Default: `['iso-8601']`
316
316
317
+
318
+
#### DURATION_FORMAT
319
+
320
+
Indicates the default format that should be used for rendering the output of `DurationField` serializer fields. If `None`, then `DurationField` serializer fields will return Python `timedelta` objects, and the duration encoding will be determined by the renderer.
321
+
322
+
May be any of `None`, `'iso-8601'` or `'django'` (the format accepted by `django.utils.dateparse.parse_duration`).
0 commit comments