WebFaction
Community site: login faq

hai,i am doing a project in Django. In that,i am keeping two date and time formats for user selection.So if the user selects a choice and save,it should be saved in database with value 0 or 1.Please refer my forms also

forms.py

Date_Format = (
    ('0', ' dd / mm / yyyy'),
    ('1', 'mm / dd / yyyy'),
)

Time_Format = (
    ('0', ' 12 hour AM / PM '),
    ('1', ' 24 hour '),
)

class SettingsForm(forms.ModelForm):
    date_format = forms.ChoiceField(widget=forms.RadioSelect(), choices=Date_Format)
    time_format = forms.ChoiceField(widget=forms.RadioSelect(), choices=Time_Format)
    class Meta:
        model = Settings
        fields = ['date_format','time_format']

I am having another page called "when page" in which we can manually add the date and time.So,what i required is if i choose a particular format in settings page,the user can view the date and time in the "when page" same format as in setting page.I need help from you to implement this

What i required is just give me tips or an example to perform this.

Any clarification in question please ask me.

Thanks, Pychu

asked 08 May '13, 06:49

pychu
3128
accept rate: 0%


The builtin Django "date" template filter allows you to specify the format when rendering a DateTime object. So, you could use an if block in your template to check your date_format and time_format and render according to that. More information is available in the Django documentation: Built-in template tags and filters

Another (and probably better) approach would be to check date_format and time_format in whatever view is rendered by your "when page", and then use Python's standard date/time formatting to convert the DateTime object to a string in the desired format before passing it to your template. See the Python datetime docs for more info.

permanent link

answered 08 May '13, 12:21

seanf
12.2k31736
accept rate: 37%

edited 08 May '13, 12:22

Can you provide me an idea that if in database,if the value is "0" date and time should be in (dd/mm/yyyy and 24hrs) format and value is "1" format should be of (mm/dd/yyyy and 12hrs am/pm)format.How to do this.Please reply me Thanks

(08 May '13, 23:22) pychu
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×901
×337
×30
×20
×2

question asked: 08 May '13, 06:49

question was seen: 2,372 times

last updated: 08 May '13, 23:22

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM