gpt4 book ai didi

python - 如何在Python代码中比较peewee日期

转载 作者:行者123 更新时间:2023-11-29 10:41:04 26 4
gpt4 key购买 nike

我喜欢将 DateTimeField 与 peewee.datetime.datetime.now 或今天进行比较,但无法做到这一点。代码片段如下。

class subinfo(peewee.Model):
sub_id = peewee.IntegerField()
active = peewee.BooleanField()
sub_type = peewee.IntegerField()
sub_cat = peewee.TextField()

class Meta:
database = locdb

class subscriber(peewee.Model):
sub_id = peewee.IntegerField(unique=True, primary_key=True)
sub_start = peewee.DateTimeField()
sub_end = peewee.DateTimeField()
ref_id = peewee.BigIntegerField()

class Meta:
database = locdb

for row in subscriber.select():
if(row.sub_start >= peewee.datetime.datetime.now):
sub1, created = subinfo.get_or_create(sub_id=row.sub_id, active=True)
if(created == False & sub1.active == False):
q = subinfo.update(active=True).where(sub_id=row.sub_id)
q.execute()
else:
subinfo.get_or_create(sub_id=row.sub_id, active=False)

但是我一直遇到以下错误

File "subsync.py", line 51, in <module>
if(row.sub_start >= peewee.datetime.datetime.now):
TypeError: '>=' not supported between instances of 'datetime.datetime' and 'builtin_function_or_method'

最佳答案

将()添加到现在使用 peewee.datetime.datetime.now() !!!

关于python - 如何在Python代码中比较peewee日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45475276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com