Monday, June 17, 2013

Re: data format value changes in database

Serge,

        I want to convert the date into (yyyy-mm-dd) this format before saving.Because while giving input in (mm/dd/yyyy) format,the date and month of the format gets interchange.
 
        I think to convert the date into (yyyy-mm-dd) and save it to database will fix.For details about this question please see this SO question http://stackoverflow.com/questions/17123054/data-format-value-changes-in-database and provide me a solution.

Thanks,
Roopa

On Monday, June 17, 2013 12:04:30 PM UTC+5:30, Sergiy Khohlov wrote:
looks like you have a problem with a form : datafield   support 2 formats, but datainput only one 

Many thanks,

Serge


+380 636150445
skype: skhohlov


On Sat, Jun 15, 2013 at 2:29 PM, <roopas...@gmail.com> wrote:
view.py

def when(request):      """"""""      if not report.manual_date:          report.manual_date = datetime.datetime.now()      if not report.manual_time:          report.manual_time = datetime.datetime.now()      if int(dateformat):          date = report.manual_date.strftime('%m/%d/%Y')      else:          date = report.manual_date.strftime('%d/%m/%Y')      reportform = ReportForm(instance=report,initial={'manual_date':date, 'manual_time':time})      if request.method == 'POST':          reportform = ReportForm(request.POST,instance=report)          if reportform.is_valid():              report = reportform.save(commit=False)              report.user = request.user              report.save()              reportform = ReportForm(instance=report,initial={'manual_date':date, 'manual_time':time})      return render_to_response('incident/when.html', {                        'date':date,                        'reportform': reportform,                        },              context_instance=RequestContext(request))  
forms.py

DATE_INPUT_FORMAT = (      ('%d/%m/%Y','%m/%d/%Y')  )    class ReportForm(forms.ModelForm):      manual_date = forms.DateField(input_formats = DATE_INPUT_FORMAT,                        widget=forms.DateInput(format = '%d/%m/%Y',attrs={'size':'15','id':'datepicker','readonly':'readonly'})) 

jQuery :

$(function () {          $( "#datepicker" ).datepicker({              showOn: "button",              buttonImage: "{{ STATIC_URL }}images/incident-reporter-icon-when.png",              dateFormat: ('dd/mm/yy'),              buttonImageOnly: true,              changeYear: true,              changeMonth: true          });      });

1.Date format should change depend upon the value in database,if value is in db,it shows the 1st format and for none ,else part is executing.

2.Formats are changing depends upon the condition.

3.I am facing problem here,if the input format is of this (%m/%d/%Y),on form post the value of date gets interchange and saved in database.If the given date is 07/06/2013 -->7th june 2013,after form post it is viewed in the field as 06/07/2013 -->6th july 2013.It is not working properly.

4.Since i am not sure where the problem is,that's the reason i updated views,forms and datepicker code.

Need help to solve this issue.

Thanks



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



On Saturday, June 15, 2013 4:59:36 PM UTC+5:30, roopas...@gmail.com wrote:
view.py

def when(request):      """"""""      if not report.manual_date:          report.manual_date = datetime.datetime.now()      if not report.manual_time:          report.manual_time = datetime.datetime.now()      if int(dateformat):          date = report.manual_date.strftime('%m/%d/%Y')      else:          date = report.manual_date.strftime('%d/%m/%Y')      reportform = ReportForm(instance=report,initial={'manual_date':date, 'manual_time':time})      if request.method == 'POST':          reportform = ReportForm(request.POST,instance=report)          if reportform.is_valid():              report = reportform.save(commit=False)              report.user = request.user              report.save()              reportform = ReportForm(instance=report,initial={'manual_date':date, 'manual_time':time})      return render_to_response('incident/when.html', {                        'date':date,                        'reportform': reportform,                        },              context_instance=RequestContext(request))  
forms.py

DATE_INPUT_FORMAT = (      ('%d/%m/%Y','%m/%d/%Y')  )    class ReportForm(forms.ModelForm):      manual_date = forms.DateField(input_formats = DATE_INPUT_FORMAT,                        widget=forms.DateInput(format = '%d/%m/%Y',attrs={'size':'15','id':'datepicker','readonly':'readonly'})) 

jQuery :

$(function () {          $( "#datepicker" ).datepicker({              showOn: "button",              buttonImage: "{{ STATIC_URL }}images/incident-reporter-icon-when.png",              dateFormat: ('dd/mm/yy'),              buttonImageOnly: true,              changeYear: true,              changeMonth: true          });      });

1.Date format should change depend upon the value in database,if value is in db,it shows the 1st format and for none ,else part is executing.

2.Formats are changing depends upon the condition.

3.I am facing problem here,if the input format is of this (%m/%d/%Y),on form post the value of date gets interchange and saved in database.If the given date is 07/06/2013 -->7th june 2013,after form post it is viewed in the field as 06/07/2013 -->6th july 2013.It is not working properly.

4.Since i am not sure where the problem is,that's the reason i updated views,forms and datepicker code.

Need help to solve this issue.

Thanks



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate