On 26 sep, 16:00, Gerard Petersen <[EMAIL PROTECTED]> wrote: > Getting closer. This works: product.period_start_date.strftime('%d-%m-%Y') > > But I definitely do not want this in all view handlers. It should go in the > model .. or the modelform. > > Thanx again! > > Gerard. > > Gerard Petersen wrote: > > Hi all, > > > I'm trying to have a formfield filled with a correlctly formatted date > > value. > > > Validation is already in place. It only accepts "dd-mm-yyyy" on submitting > > but when it gets the existing value from the model it shows it in the > > formfield like "yyyy-mm-dd" > > > So the sequence is almost complete. But where do I format the value so the > > formfield shows the correct formatted value when editing. In the model, the > > form or the view method? > > > Thanx a lot. > > > Gerard. > > -- > urls = { 'fun': 'www.zonderbroodje.nl', 'tech': 'www.gp-net.nl'}
Hi Gerard, the DateTimeInput widget already accepts a format parameter. What I do is I have a subclass of ModelForm that in its init goes over the fields and replaces the widget for Datefields with a datetimeinput with the correct format. I also change the input format their (I prefer dd/mm/yyyy). something like: for field in self.fields: if isinstance(self.fields[field], forms.Datefield): self.fields[field].input_formats = settings.DATE_INPUT_FORMATS self.fields[field].widget = forms.DateTimeInput(format = settings.DATE_OUTPUT_FORMAT) as you can see, I put the formats in my settings file, but of course you could just plug them right in here too. I am not sure this is the best way to do this, but maybe this helps. Koen --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---