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

后端 未结 2 382
梦谈多话
梦谈多话 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:39

    If you look in django/forms/extras/widgets.py where SelectDateWidget is defined the render function contains this snippet of code.

     90         output = []
     91         for field in _parse_date_fmt():
     92             if field == 'year':
     93                 output.append(year_html)
     94             elif field == 'month':
     95                 output.append(month_html)
     96             elif field == 'day':
     97                 output.append(day_html)
     98         return mark_safe(u'\n'.join(output))
    

    _parse_date_fmt uses get_format('DATE_FORMAT')

    It looks like DATE_FORMAT can be set in the settings.py

    https://docs.djangoproject.com/en/dev/ref/settings/#date-format

提交回复
热议问题