我想知道如何从 DateTimeField 中提取年、月、日、小时和分钟?
我要提取信息的 datimefield 称为“redemption_date”,模型的代码是这样的:
from django.db import models
from datetime import datetime, timedelta
class Code(models.Model):
id = models.AutoField(primary_key=True)
code_key = models.CharField(max_length=20,unique=True)
redemption_date = models.DateTimeField(null=True, blank=True)
user = models.ForeignKey(User, blank=True, null=True)
# ...
def is_expired(self):
expired_date = datetime.now() - timedelta( days=2 )
my_redemtion_date = self.redemption_date
if self.redemption_date is None:
return False
if my_redemtion_date < expired_date:
return True
else:
return False
提前致谢!