我有这样的模型
class Foo(models.Model):
bet = models.IntegerField()
end_date = models.DateTimeField() \\some date in the future
is_canceled = models.BooleanField(default=False)
当 end_date = datetime.now()
时,我需要自动设置 is_canceled = True答案 0 :(得分:3)
您可以创建now = datetime.now()
Foo.objects.filter(end_date__lte=now).update(is_canceled=True)
定期从class Foo(models.Model):
bet = models.IntegerField()
end_date = models.DateTimeField() \\some date in the future
@property
def is_canceled(self):
if self.end_date <= datetime.now():
return True
else:
return False
some_foo = Foo.objects.first()
if some_foo.is_canceled:
...
运行并更改字段值
.select-hidden {
display: none;
visibility: hidden;
padding-right: 10px;
}
.select {
cursor: pointer;
display: inline-block;
position: relative;
font-size: 16px;
color: $select-color;
width: $select-width;
height: $select-height;
border-radius: 5px;
}
但让这个领域变得更加动态
更好EntityManager