LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-08-2011, 02:15 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
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?
 
Old 10-08-2011, 01:01 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
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.
 
  


Reply

Tags
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:46 PM.

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