【问题标题】:django get data with filter todaydjango 今天用过滤器获取数据
【发布时间】:2021-08-29 23:37:22
【问题描述】:

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

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()

有什么建议吗?

【问题讨论】:

标签: django database django-models django-templates aggregate


【解决方案1】:

你可以试试这个。

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

【讨论】:

    猜你喜欢
    • 2014-06-13
    • 2012-06-30
    • 2021-05-07
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 2021-08-27
    • 1970-01-01
    相关资源
    最近更新 更多