Thanks everybody. I changed this : birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date', required=False ),
for this : birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date', required=False, widget=forms.DateInput(format='%d/%m/%Y') ) And it all works very good. But there's something else fishy here. If i tried this: birth_date = forms.DateField(label='Birth Date', required=False, widget=forms.DateInput(format='%d/%m/%Y') ) Then it did not save in correct format again. But guess in which format did it save? %m/%d/%Y Why the hell though? could this be a minor bug in django code? Alan On Aug 4, 5:19 am, Margie <margierogin...@yahoo.com> wrote: > I did this with a combination of a DateWidget and a small .js file > that calls the jquery datepicker on each widget. I don't use the same > date format as you, but you should be able to modify it to fit your > need. > > It's amazing how easy the code below looks, but I can tell you it took > me most of a day to figure out how to use the jquery datepicker, how > to create widgets, and how to just put it all together so that it > works! > > class DateWidget(widgets.DateInput): > class Media: > js = ('js/jquery.js', > "js/date.js", > "js/jquery.datePicker.min-2.1.2.js", > "js_custom/date_widget.js", > ) > > css = {'all' : ('css/date_picker.css', 'css/ > date_picker_chipvision.css') } > > def __init__(self, attrs={}): > attrs['class'] = 'my_class_to_identify_datewidget' > super(DateWidget, self).__init__(format='%m/%d/%Y', > attrs=attrs) > > Then I have a small .js file (js_custom/date_widget.js) that has this: > $(document).ready(function() { > Date.firstDayOfWeek = 0; > Date.format = 'mm/dd/yyyy'; > $('.my_class_to_identify_datewidget').datePicker(); > }); > > I'm not sure if settings Date.firstDayOfWeek and Date.format the way I > do is the best way to do it, but I could not figure out how to do it > via params to datePicker. > > Anyway, hope this helps. > > Margie > > On Aug 3, 11:08 am, zayatzz <alan.kesselm...@gmail.com> wrote: > > > Hello. > > > I have this in my form (modelform) for birth_date field: > > birth_date = forms.DateField(('%d/%m/%Y',), label='Birth Date', > > required=False ), which overrides this in model: > > > birth_date = models.DateField(help_text="birth date", > > verbose_name="Birth date", blank=True, null=True, ) > > > I also have jquery datepicker on the page which sets date in the same > > format (%d/%m/%Y). But the form saves date in %Y-%m-%d format in > > database, which means that when user returns to reedit the data, the > > form wont validate and the user has to set the date again. > > > Can anyone tell me what causes such behaviour and how to fix/change > > it? My database in mysql - no idea if this is relevant. > > > Alan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---