我有以下型号。
class Room(models.Model):
room_number = models.PositiveSmallIntegerField(
validators=[MaxValueValidator(1000), MinValueValidator(1)],
primary_key=True
)
class TimeSlot(models.Model):
room = models.ForeignKey(Room, on_delete=models.CASCADE)
available_from = models.TimeField()
available_till = models.TimeField()
这是我的views.py
keys = ['room', 'available_from_gte', 'available_till_lte']
values = [room_obj, available_from, available_till]
# room_obj contains object of Room model. available_from and available_till contains time in 02:00:00 format.
parameters = {}
for key, value in zip(keys, values):
if value is not None and value !=[] and value != '':
parameters[key] = value
time_slots_list = TimeSlot.objects.filter(**parameters)
在运行上面的代码时,我得到了以下错误。
Cannot resolve keyword 'available_from_gte' into field. Choices are: available_from, available_till, id, room, room_id
有人能帮我一下吗?
1条答案
按热度按时间5lwkijsr1#
我相信你要找的是
available_from__gte
。注意gte前面的双下划线。访问相关字段和查找,如in
和gte
,在字段名中用两个下划线表示。