How do you change the order of Django's SelectDateWidget to day, month, year?

后端 未结 2 380
梦谈多话
梦谈多话 2021-01-13 07:14

This is the form:

from django.forms.extras.widgets import SelectDateWidget


class EntryForm(forms.ModelForm):

    class Meta():
        model = Entry

             


        
2条回答
  •  走了就别回头了
    2021-01-13 07:42

    From the source code of this widget I see the the order of dropdowns is defined by DATE_FORMAT setting:

        format = get_format('DATE_FORMAT')
        escaped = False
        output = []
        for char in format:
            if escaped:
                escaped = False
            elif char == '\\':
                escaped = True
            elif char in 'Yy':
                output.append(year_html)
            elif char in 'bFMmNn':
                output.append(month_html)
            elif char in 'dj':
                output.append(day_html)    
    

    Try to change DATE_FORMAT in settings.py to j N, Y for example.

提交回复
热议问题