Unable to save another date format in django

I am working on a form and have a date field. I want to save a different date format for the date field instead of django. I get the date "01-jan-2016" and want to save as in my database. When I try to save the same format, an error occurs

[u"'07-Dec-2016' value has an invalid date format. It must be in YYYY-MM-DD format."].

I know this question has already been asked, but they do not solve my problem.

views.py

post_date = request.POST['date']

lead_obj = CustomerLeads.objects.create(posting_date = post_date)

my models.py

class Leads(models.Model):
    customer_name = models.CharField(max_length=50,null=True, blank=True)
    title = models.CharField(max_length=100, null=True, blank=True)
    posting_date = models.DateField()
+4
source share
3 answers

In your view.py try the following:

from dateutil import parser

d = parser.parse("07-December-2016")
print d
d = d.strftime("%d-%b-%Y")
print d

Conclusion:

2016-12-07 00:00:00
07-Dec-2016

It will handle various formats.

+1
source

Mysql

DATE , . MySQL DATE "YYYY-MM-DD". - "1000-01-01" "9999-12-31".

Postgresql

, ISO 8601, SQL-, POSTGRES . , , . DateStyle MDY, , DMY, -- YMD -.

, postgresql , . ?

INSERT INTO stackoverflow_heatwatchlist(next_date_from, next_date_to) 
VALUES('1999 Jan 05','2001 Jun 06');

, "2001-06-06" "1999-01-05"

SQlite

, , , , sqlite . sqlite . django .

SQL Server

, . . . ? '1999-01-05'

, , , , , - , . , django python .

, . -, unix , , , - - .

-, CharField , . , , .

+1

'%d-%b-%Y' DATE_INPUT_FORMATS .

0

Source: https://habr.com/ru/post/1663913/


All Articles