Django Admin date pickers ignoring FIRST_DAY_OF_WEEK?

I wonder if someone else could see if they have this issue, or whether I’ve set up something wrong.

In settings.py I’ve set the FIRST_DAY_OF_WEEK setting to be 1, which is Monday:

FIRST_DAY_OF_WEEK = 1

But in the site’s Django Admin, the JS date pickers start the week on Sunday:

I think this was initially fixed in this issue in 2006 and an update to the docs about it in 2011. So has this regressed since, or is there something else I should be doing regarding internationalisation to get it working?

From the referenced docs:

This value is only used when not using format internationalization, or when a format cannot be found for the current locale.

Are either of these conditions true?

I don’t know. I have USE_I18N = False in my settings. What else should I be looking for?

<conjecture>
This turns out to be far more interesting than I thought - and may possibly be a documentation issue associated with the changes made for Django 4.0 (See Django 4.0 release notes | Django documentation | Django)

As you have pointed out above, setting USE_I18N = False does not appear to affect the calendar widget in the admin. (I don’t have any idea how it this would affect anything else. I don’t have anything rendering a date that would pay attention to the first day of the week.)

The get_format function in django.utils.formats still makes a reference to USE_L10N and _USE_L10N_INTERNAL - neither of which are defined in django.conf.global_settings any more.

It now appears that to make this change, you need to supply a custom formats.py file, with the change made inside of it. (Adding said formats.py file does change the admin widget, so at least that works.)

The ticket: #35990 (settings.TIME_INPUT_FORMATS never gets used since the removal of USE_L10N) – Django offers the suggestion of using a language that doesn’t have this set, but there is no supplied locale that doesn’t have this defined.

(Also, Django 5.0 release notes | Django documentation | Django documents that USE_L10N has been removed, which means the comment made in #35293 (Django 5.x changes the date format on an <input type="date"> from "2012-10-01" to "01/10/2012") – Django may not be valid any more.)
</conjecture>

At this point, I think I’ve taken this about as far as I can.

<opinion>
Something doesn’t seem right here - but what to do about it is beyond me.

I think there’s a case that could be made that there’s some work to do in this area. But whether that’s just some documentation cleanup, or actual code changes to the affected functions… :man_shrugging:
</opinion>

Thanks Ken. I had a poke around the code too but am not much wiser as to where this is going wrong. I created a ticket.

To add some more for others reading this thread,

<conjecture>
It appears to me that the removal of USE_L10N has effectively deactivated settings related to formats that are documented in Settings | Django documentation | Django

I’ve been unable to find any way to get those settings to directly take effect. (It’s not just the FIRST_DAY_OF_WEEK setting - a handful of tickets have been created identifying variations on this basic issue.)
</conjecture>

Assuming the above is correct, I see at least two options:

  • Remove those settings from the settings docs, since they don’t do anything when placed in settings.py.
  • Change the code to allow the settings to “override” or “supersede” what is defined in the formats.py file.

<opinion>
Removing the entries from the docs does avoid some confusion. But then the solution of requiring that these settings be changed in individual formats.py files feels “unsatisfactory”. (Do I really need to copy / change all the formats.py files in django.conf.locale if I need this to work across translations?)

I think I’d be more in favor of allowing the settings.py entries to override the formats.py, but I’m not sure what that would look like in practice.
</opinion>

I totally agree with your opinion. Removing the entries from the docs is unsatisfactory and djangonauts may want to customize those settings as well.

On my local, I changed the get_format function in the formats.py. I use the settings from django.conf to get the USE_I18N from the settings.py, and I set use_l10n in the get_format function as the value of USE_I18N when the use_l10n is None. It changed the FIRST_DAY_OF_WEEK when I set USE_I18N=False.

if use_l10n is None:
        use_l10n = getattr(settings, 'USE_I18N')

This is my basic idea to fix the issues related to the USE_L10N entry for v5.0 or more. But the names do not match each other. I’ll keep my eye on this topic and try to modify/remove the codes related to the USE_L10N.