django - Change DateInput widget's format to SHORT_DATE_FORMAT -


i'm trying set format of dateinput short_date_format. however, following code not work work.

forms.py

from django.conf.global_settings import short_date_format  class eventform(modelform):     # ...     startdate = forms.datefield(         widget=forms.dateinput(             format=short_date_format         )     ) 

in views.py, example entry read database , form created using form = eventform(instance=event1). template shows widget using {{form.startdate}}. input shows correctly, it's value not date "m/d/y".

it work if i'd set format='%m/%d/%y', however, defeats purpose of locale-aware short_date_format. how can solve that?

a possible solution overwrite dateinput widget follows.

from django.template.defaultfilters import date  class shortformatdateinput(dateinput):      def __init__(self, attrs=none):         super(dateinput, self).__init__(attrs)      def _format_value(self, value):         return date(value, formats.get_format("short_date_format")) 

it overwrites super constructor date format cannot changed manually anymore. instead i'd show date defined in short_date_format. that, _format_value method can overwritten reuse date method defined django.templates.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -