django datefield没有正确存储在MYSQL数据库中

时间:2018-01-08 10:26:46

标签: python mysql django

我正在使用django和MYSQL。下面是我的models.py:

enter code here

    from django.db import models 
    from django.utils import timezone 
    import datetime
    from django.utils.translation import gettext as _ 
    from bootstrap4_datetime.widgets import DateTimePicker 
    from django import forms

class Post(models.Model):
    WEEKDAYS=(
        ('Mon','Monday'),
        ('Tue','Tuesday'),
        ('Wed','Wednesday'),
        ('Thu','Thursday'),
        ('Fri','Friday'),
        )
    TIMES=(
        ('morning','上午'),
        ('afternoon','下午'),
        ('night','晚上'),
        )
    CUSTOMERS=(
        ('中兴','ZTE'),
        ('比特大陆','BITMAIN'),
        ('松果','PINECONE'),
        ('飞思卡尔','FREESCALE'),
        ('大唐','DATANG'),
        )
    weekday = models.CharField(max_length=50,default='Mon',choices=WEEKDAYS)
    time = models.CharField(max_length=50,default='morning',choices=TIMES)
    customer = models.CharField(max_length=50,default='ZTE',choices=CUSTOMERS)
    pub_date = models.DateField(_("Date"), default=datetime.datetime.now().date)


class Meta:
    ordering = ('-pub_date',)

def __unicode__(self):
    return self.pub_date       

这是数据库记录:

13  2018-01-02 00:00:00.000000  中兴  morning Mon
14  2018-01-08 00:00:00.000000  中兴  morning Mon

数据库表显示全职,但我认为datefield只返回格式:YY-MM-DD。如何以YY-MM-DD格式存储日期。

谢谢!

0 个答案:

没有答案