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
fromdjango.dbimportmodelsfromdjango.utilsimporttimezoneclassMyModel(models.Model):
user_id=models.ForeignKey(
User,
null=True,
on_delete=models.SET_NULL,
verbose_name=_("User identifier"),
)
created_at=models.DateField(
default=timezone.now,
verbose_name=_("Date of creation"),
)
some_other_field=models.IntegerField(
verbose_name=_("Some other field"),
)
The widget looks as follow when it's set to the 9th of January 2024:
But it should be 09.01.2024 because the browser language is set to French. And when I watch at what is stored in the db, it's written 2024-09-01 (1st September 2024).
So I have to hard code that in the widget options in MyForm() class:
Then it works within a French browser environment.
But now, when browsing the app using an English browser, the widget stays as it is coded (this is normal I guess):
and the user can no more submit the form because of a server error:
form.errors: <ul class="errorlist"><li>created_at<ul class="errorlist"><li>Enter a valid date.</li></ul></li></ul>
Expected behavior
So I would like to know if it's possible to make the DatePickerInput() widget be aware of the locale?
(Same goes for the DateTimePickerInput() widget).
If yes, how precisely?
For the moment, I'm thinking it's a bug or a missing feature.
Thanks a lot!
Setup Information (please complete the following information):
I have the same problem.
All but hard coding the locale and format in each DatePickerInput's widget options fails.
It seems, at least in my case, that datepicker-plus somehow fetches the global options from the server it is running on:
Hello,
I'm using a
DatePickerInput()
widget in a form in order to let a user select a date using this nice calendar widget within a django 4.2 application.The locale is set as follow in the
settings.py
file:The form is as follow:
And the corresponding app model is:
The widget looks as follow when it's set to the 9th of January 2024:
![image](https://private-user-images.githubusercontent.com/19967599/294914860-a90dde3a-a43c-4144-baf6-043f813d28a6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjAzODgsIm5iZiI6MTczOTQ2MDA4OCwicGF0aCI6Ii8xOTk2NzU5OS8yOTQ5MTQ4NjAtYTkwZGRlM2EtYTQzYy00MTQ0LWJhZjYtMDQzZjgxM2QyOGE2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE1MjEyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI1ZTI0Njk5NDkwMzVkYmYxMGJlNmUxM2EwNDQwZGJhYWQyODI4NTQwOWQ5ZDU4NWI5ODJkNDkzMWMzZmIyOTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.xj0aQfXe3TE2zj-pjzirLBiaPwaEF-O30RpP_5x-SIg)
But it should be
09.01.2024
because the browser language is set to French. And when I watch at what is stored in the db, it's written2024-09-01
(1st September 2024).So I have to hard code that in the widget options in
MyForm()
class:(There is no fancy templating:
and nothing special in the
views
)
Then it works within a French browser environment.
But now, when browsing the app using an English browser, the widget stays as it is coded (this is normal I guess):
![image](https://private-user-images.githubusercontent.com/19967599/294922564-3bdb0ef7-c4b2-443c-9e3c-d08602a919a8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjAzODgsIm5iZiI6MTczOTQ2MDA4OCwicGF0aCI6Ii8xOTk2NzU5OS8yOTQ5MjI1NjQtM2JkYjBlZjctYzRiMi00NDNjLTllM2MtZDA4NjAyYTkxOWE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE1MjEyOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJjOWZhMGY2MGM1MTE5YmY3NDZkOGU3ODRhYjk1YjcwOTZmNmFhMzhkNjJjZjVjYjIxMjM1MjhmNzExOTJhMmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.kF37MPycrVxYlRLs8xNJWCKcvxy6e25pw2tECKrJBOY)
and the user can no more submit the form because of a server error:
Expected behavior
So I would like to know if it's possible to make the
DatePickerInput()
widget be aware of the locale?(Same goes for the
DateTimePickerInput()
widget).If yes, how precisely?
For the moment, I'm thinking it's a bug or a missing feature.
Thanks a lot!
Setup Information (please complete the following information):
[x] I have followed the configuration instructions and checked out the
common error troubleshooting page.
The text was updated successfully, but these errors were encountered: