问题描述
我正在尝试使用注释的生成日期字段进行查询/过滤。
这是我的查询:
trip = Booking.objects.annotate(
end_date=Concat(
Extract('start_date','year'),Value('-'),Extract('start_date','month'),'day') + F('itinerary__days'),output_field=DateField()
)
)
expired = booking.filter(end_date__gte=datetime.today())
但是解雇了我以下错误:
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
我对此进行了研究,该错误与PostgreSQL有关。
我没有解决此问题的方法
这些是我的模特
class Itinerary(models.Model):
days = models.PositiveSmallIntegerField(_("Days"),null=True,blank=True)
class Booking(models.Model):
itinerary = models.ForeignKey(
Itinerary,on_delete=models.CASCADE
)
start_date = models.DateField(_("Start Date"),blank=True)
def get_end_date(self):
return self.start_date + datetime.timedelta(days=self.itinerary.days)
我不知道如何解决这个问题。
我没有名为end_date
的字段,但我要通过增加行程表中的天数来标注end_date
谁能告诉我查询不起作用的可能原因是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)