【问题标题】:get max date DJANGO queryset获取最大日期 DJANGO 查询集
【发布时间】:2015-12-08 13:31:14
【问题描述】:

我需要从模型中提取最大日期。我在 y 查询集中使用聚合

fm = Codigo_Corto_Hist.objects.filter(codigo=cod).filter(estado=0).aggregate(Max('fecha_cambio'))

但我收到了一个字典 {'fecha': datetime.date(2015, 1, 1)},我只需要日期的值。

还有另一种获取值的方法,而不是字典,或者我如何从字典中提取值。

提前致谢

【问题讨论】:

  • my_dict["fecha"] ?
  • 谢谢@JoranBeasley。我不熟悉字典。我想我需要阅读如何处理字典

标签: python django django-views django-queryset


【解决方案1】:

试试:

from django.db.models import Max
fm = Codigo_Corto_Hist.objects.filter(codigo=cod).filter(estado=0).aggregate(Max('fecha_cambio')).values_list('fecha', flat=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 2018-10-18
    • 1970-01-01
    • 2012-10-27
    相关资源
    最近更新 更多