【问题标题】:Value has an invalid format and must be of the form YYYY-MM-DD HH: MM值的格式无效,必须采用 YYYY-MM-DD HH: MM 格式
【发布时间】:2017-07-15 08:36:56
【问题描述】:

我正在使用 django 1.6,但在代码的最后一行出现错误:

start__gte=min_date, start__lte=max_date)

这里是错误:

[U "'start__min' value has an invalid format and must be of the form YYYY-MM-DD HH: MM [: ss [.uuuuuuu]] [TZ]"

这是我的功能:

def person_coming_events(person):
    active_seasons = Season.objects.filter(is_active=True)
    min_date, max_date = active_seasons.aggregate(Min('start'), Max('end'))
    production_ids = SeasonProduction.objects.filter(season__in=active_seasons).values_list('production_id', flat=True)
    return Activity.objects.filter(production_id__in=production_ids, cast__person=person,
                                   start__gte=min_date, start__lte=max_date)

【问题讨论】:

    标签: python django datetime time aggregate


    【解决方案1】:

    聚合 返回一个包含两项的字典。像你一样解包字典,只返回字典键min_datemax_date;这意味着它们被分配给字符串'start__min''end__max',它们不是有效的日期值。

    您应该访问相应的字典键并将日期值分配给您的变量:

    agg = active_seasons.aggregate(Min('start'), Max('end'))
    min_date, max_date = agg['start__min'], agg['end__max']
    

    顺便说一句,你应该考虑从 Django1.6 升级

    【讨论】:

      猜你喜欢
      • 2021-11-26
      • 2023-02-23
      • 2019-02-02
      • 2015-02-26
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-24
      相关资源
      最近更新 更多