LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Django - How to set up initial value for a datetime field in a form? (https://www.linuxquestions.org/questions/programming-9/django-how-to-set-up-initial-value-for-a-datetime-field-in-a-form-907067/)

eantoranz 10-08-2011 02:15 AM

Django - How to set up initial value for a datetime field in a form?
 
Hi!

I'm playing around with django so I'm far from being an expert. I'm just learning, so keep the explanations simple if possible.

I'm creating a form (extending from forms.Form) and I have a couple of datetime fields in it:

Code:

class ServiceRequestForm(forms.Form):
    name = forms.CharField(label="Name", max_length = 255)
    description = forms.CharField(label="Description", widget=forms.Textarea)
    openingDate = forms.DateTimeField(label="Opening Date", widget=widgets.AdminSplitDateTime)
    closingDate = forms.DateTimeField(label="Closing Date", widget=widgets.AdminSplitDateTime)

Now, I'm able to set the initial value for both CharFields, but not the datetime fields. How can I do that?

eantoranz 10-08-2011 01:01 PM

Given that I'm working with models, I switched the form to extend from ModelForm and now the initial value for DateTime fields is set correctly.... the question of how to do it, say, by hand remains open. I'll be revisiting it later.


All times are GMT -5. The time now is 02:55 AM.