gpt4 book ai didi

Python/Django日期查询: Unsupported lookup 'date' for DateField or join on the field not permitted

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:07 27 4
gpt4 key购买 nike

我有一个简单的方法。条目是时间表应用程序中的条目,员工可以在其中输入他们的时间。

class Entry(m.Model):
""" Represents an entry in a time_sheet. An entry is either for work, sick leave or holiday. """
# type choices
WORK = 'w'
SICK = 's'
VACATION = 'v'
type_choices = (
(WORK, 'work'),
(SICK, 'sick leave'),
(VACATION, 'vacation'),
)
# meta
cr_date = m.DateTimeField(auto_now_add=True, editable=False, verbose_name='Date of Creation') # date of creation
owner = m.ForeignKey(User, editable=False, on_delete=m.PROTECT)
# content
type = m.CharField(max_length=1, choices=type_choices, default='w')
day = m.DateField(default=now)
start = m.TimeField(blank=True) # starting time
end = m.TimeField(blank=True) # ending time
recess = m.IntegerField() # recess time in minutes
project = m.ForeignKey(Project, on_delete=m.PROTECT)

@classmethod
def get_entries_for_day(cls, user, day):
""" Retrieves any entries for the supplied day. """
return Entry.objects.filter(day__date=day, owner=user).order_by('start')

但是,当我尝试像这样运行我的项目时,它以以下错误代码终止:

"Unsupported lookup 'date' for DateField or join on the field not permitted."

我不太明白这个消息。指定的字段是一个没有进一步限制的日期字段。任何提示将不胜感激。

最佳答案

在 DateField 上没有 __date 查找之类的东西;该字段已经是一个日期。

不清楚您要将此字段与什么进行比较。您传递给该方法的日期是整数还是日期?如果它也是一个日期,那么您应该直接比较它们。

关于Python/Django日期查询: Unsupported lookup 'date' for DateField or join on the field not permitted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37972938/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com