Python django如何在kwargs内使用范围
我试图在两个日期之间过滤我的查询集,但我似乎不明白为什么这不起作用 这是我的密码Python django如何在kwargs内使用范围,python,django,Python,Django,我试图在两个日期之间过滤我的查询集,但我似乎不明白为什么这不起作用 这是我的密码 kwargs = { '{0}__{1}'.format(arg1, 'exact'): arg2, '{0}__{1}'.format('deleted', 'isnull'): True, '{0}__{1}'.format('event_date', 'range'): {date1, date2} } table =
kwargs = {
'{0}__{1}'.format(arg1, 'exact'): arg2,
'{0}__{1}'.format('deleted', 'isnull'): True,
'{0}__{1}'.format('event_date', 'range'): {date1, date2}
}
table = GeTable(Ge.objects.filter(**kwargs))
我希望能够筛选我的查询集,使其只包含date1和date2之间的记录。有人能给我指出正确的方向吗?你传递了一个2元组,所以:
kwargs = {
'{0}__{1}'.format(arg1, 'exact'): arg2,
'{0}__{1}'.format('deleted', 'isnull'): True,
'{0}__{1}'.format('event_date', 'range'): (date1, date2)
}
table = GeTable(Ge.objects.filter(**kwargs))
kwargs={
“{0}{1}”。格式(arg1,'exact'):arg2,
“{0}{1}”。格式('deleted','isnull'):True,
“{0}{1}”。格式('event_date','range'):(date1,date2)
}
table=GeTable(Ge.objects.filter(**kwargs))
通过使用集合,顺序可以在不同的运行之间变化,因此有时它会起作用,有时则不会(大约50%)。这是因为随机散列算法,出于安全原因,它被用作保护措施。您传递了一个2元组,因此:
kwargs = {
'{0}__{1}'.format(arg1, 'exact'): arg2,
'{0}__{1}'.format('deleted', 'isnull'): True,
'{0}__{1}'.format('event_date', 'range'): (date1, date2)
}
table = GeTable(Ge.objects.filter(**kwargs))
kwargs={
“{0}{1}”。格式(arg1,'exact'):arg2,
“{0}{1}”。格式('deleted','isnull'):True,
“{0}{1}”。格式('event_date','range'):(date1,date2)
}
table=GeTable(Ge.objects.filter(**kwargs))
通过使用集合,顺序可以在不同的运行之间变化,因此有时它会起作用,有时则不会(大约50%)。这是因为随机散列算法出于安全原因被用作保护措施