【发布时间】:2022-08-22 22:50:27
【问题描述】:
我在 django 模型中有一个字段:“created_at”,它是带有时区的日期时间(例如:2022-08-09 14:03:18.467482+02)。在我的应用程序中,我有一个表单,用户仅选择日期(例如:2022-06-09)。
我试图在我的视图中过滤该字段,如下所示:
res = MyObject.objects.all()
res = res.filter(created_at = date)
我收到以下错误:RuntimeWarning: DateTimeField Mybject.created_at received a naive datetime (2022-06-09 00:00:00) while time zone support is active.
用用户输入日期过滤我的对象的最佳方法是什么?我是否需要将时区添加到用户选择的日期以及如何添加?