django 今天用过滤器获取数据

django get data with filter today

我想今天创建设备 这是我的模型 :

class Device(models.Model):
    hostname = models.CharField(max_length=200, null=True)
    password = models.CharField(max_length=200, null=True)
    type = models.CharField(max_length=200,choices=dtype, null=True)
    ipadress = models.CharField(max_length=200, null=True)
    date_created = models.DateTimeField(auto_now_add=True, null=True)

我试过这个视图但没有用:

device_today = Device.objects.filter(date_created=today).count()

有什么建议吗?

你可以试试这个。

import datetime
today=datetime.date.today()
Device.objects.filter(date_created__date=today)