【发布时间】:2018-02-28 13:21:56
【问题描述】:
我有下表:
class OverallAdvise(mixins.OrdMixin, mixins.EqMixin, models.Model):
section = models.ForeignKey('quest.Section',
on_delete=models.CASCADE,
related_name='section_owner')
range_start = models.IntegerField(blank=True, null=True)
range_end = models.IntegerField(blank=True, null=True)
get_advise = models.CharField(max_length=500)
然后,在序列化程序中,我尝试根据计算的分数选择get_advise。
我的查询是:
get_overall_advise = OverallAdvise.objects.filter(section_id = section_id, range_start__gte = section_overall_score, range_end__lte = section_overall_score).values("get_advise")
但它不起作用。
当我在查询中仅使用 section_id 时,它可以正常工作。
section_id=6 和 section_overall_score=8 已给出。
我需要像range_start<=6<=range_end 这样的东西。
你能帮帮我吗?
【问题讨论】:
-
你能告诉我
range_start__gte = section_overall_score, range_end__lte = section_overall_score这是什么逻辑吗?您只想根据自己的逻辑选择 8 section_overall_score。 -
@NeErAjKuMaR 我想要类似的东西:
range_start<=6<=range_end -
但是根据你的逻辑你不会得到输出。更新代码如下
range_start__lte = section_overall_score, range_end__gte = section_overall_score -
@NeErAjKuMaR 谢谢!如果
section_overall_score在0,12范围内,则该示例有效。如果分数更高,我仍然会出错。即使范围值存储在我的数据库中。