Opened 3 weeks ago

Closed 3 weeks ago

#35978 closed Uncategorized (invalid)

Django Rest Framework - How do i actually use a custom date format?

Reported by: Federico_Bucciero Owned by:
Component: Documentation Version: 5.1
Severity: Normal Keywords: DATE_INPUT_FORMAT
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi there,
using drf, i developed a simple api for an internal project.
I got asked to change the format of the date field from the ISO format "%Y-%m-%d" to the format '%d.%m.%Y'.
I read and re-read the documentation, jumped from forum and discussion, but i can't find a working solution.
The project structure is:
project/

api/

init.py
formats/

init.py
it/

init.py
formats.py

migrations/
admin.py
apps.py
...

backend/

init.py
asgi.py
settings.py
urls.py
wsgi.py

in project/backend/settings.py i have set
LANGUAGE_CODE = 'it'
FORMAT_MODULE_PATH = ['api.formats',]

and in project/api/formats/it/formats.py i have set
DATE_INPUT_FORMATS = [

'%d/%m/%y',
'%d/%m/%Y',
'%d.%m.%Y',
'%d.%m.%y',
'%Y-%m-%d',
# etc

]

but still doesn't work, and fails my request, asking for a date in format '%Y-%m-%d'
The documentation doesn't help really much undestanding how to properly customize the format, as this "The locale-dictated format has higher precedence and will be applied instead." tries to imply that customization is impossible.

Django version: 5.1.4
djangorestframework version: 3.15.2

Change History (1)

comment:1 by Sarah Boyce, 3 weeks ago

Resolution: invalid
Status: newclosed

Hello, this report seems better suited to be a support request for DRF. The best place to get answers to your issue is using any of the user support channels from this link.

Since the goal of this issue tracker is to track issues about Django itself, I'll be closing this ticket as invalid following the ticket triaging process. Thank you!

Note: See TracTickets for help on using tickets.
Back to Top