加一个时间字段,修改表 models.py

    1. class info(models.Model):
    2. name = models.CharField(max_length=16)
    3. age = models.IntegerField(default=100)
    4. date = models.DateTimeField()

    写入到数据库

    1. python manage.py makemigrations
    2. python manage.py migrate

    时间操作

    1. # 新增
    2. # import datetime
    3. # now = datetime.datetime.now()
    4. # models.info.objects.create(name='wangwu',age=10086,date=now)
    5. # 查询
    6. # obj = models.info.objects.filter(date__year=2000,date__month=12,date__day=1)
    7. # print(obj.values())