django 无法将关键字“available_from_gte”解析为字段,选项包括:可用起始日期、可用截止日期、标识、房间、房间标识

vi4fp9gy  于 2022-12-14  发布在  Go
关注(0)|答案(1)|浏览(114)

我有以下型号。

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

有人能帮我一下吗?

5lwkijsr

5lwkijsr1#

我相信你要找的是available_from__gte。注意gte前面的双下划线。访问相关字段和查找,如ingte,在字段名中用两个下划线表示。

相关问题