Opened 8 years ago
Closed 8 years ago
#27364 closed Bug (invalid)
DATE_INPUT_FORMATS is not working
Reported by: | Alex | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.10 |
Severity: | Normal | Keywords: | date |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Per the Django Docs, in settings.py if I set USE_L10N to false, I should be able to override the supported date formats. My settings.py has the following:
LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = False USE_L10N = False USE_TZ = False DATE_INPUT_FORMATS = [ '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06' '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006' '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006' '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006' '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' ]
I have a model that looks like the following:
class DateTest(models.Model): date = models.DateField(blank=True, null=True)
When I run the following command, i get an error:
>>> DateTest.objects.create(date='09/01/2016') Traceback (most recent call last): File "<console>", line 1, in <module> File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/query.py", line 399, in create obj.save(force_insert=True, using=self.db) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/base.py", line 796, in save force_update=force_update, update_fields=update_fields) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/base.py", line 824, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/base.py", line 908, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/base.py", line 947, in _do_insert using=using, raw=raw) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/query.py", line 1045, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1053, in execute_sql for sql, params in self.as_sql(): File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1006, in as_sql for obj in self.query.objs File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1006, in <listcomp> for obj in self.query.objs File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1005, in <listcomp> [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 945, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 755, in get_db_prep_save prepared=False) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1280, in get_db_prep_value value = self.get_prep_value(value) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1275, in get_prep_value return self.to_python(value) File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1250, in to_python params={'value': value}, django.core.exceptions.ValidationError: ["'09/01/2016' value has an invalid date format. It must be in YYYY-MM-DD format."]
Note:
See TracTickets
for help on using tickets.
My understanding is that only form fields (rather than model fields) handle those formats (e.g. DateField).