Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-08-2011, 02:15 AM   #1
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,045
Blog Entries: 1

Rep: Reputation: 83
Django - How to set up initial value for a datetime field in a form?


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:

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?
Old 10-08-2011, 01:01 PM   #2
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,045
Blog Entries: 1

Original Poster
Rep: Reputation: 83
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.


datetime, django, forms, init value, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form field validation using php esteeven Programming 2 09-10-2009 02:15 PM
form field hints Joachim Schrader Linux - Newbie 2 09-30-2008 03:38 PM
Convert Time String to DATETIME field Centinul Programming 2 09-25-2006 07:20 PM
Mysql/PHP query problem with datetime field. Pcghost Programming 2 11-11-2003 12:24 PM
html form current datetime meluser Programming 27 04-16-2003 06:51 PM

All times are GMT -5. The time now is 04:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration