from django.db import models from django.utils import timezone import datetime # Create your models here. class Question(models.Model): question_text=models.CharField(max_length=200) pub_date=models.DateTimeField('date published') def __str__(self): # __unicode__ on Python 2 return self.question_text def was_published_recently(self): # return self.pub_date >= timezone.now()- datetime.timedelta(days=1) if self.pub_date >= timezone.now()- datetime.timedelta(days=3): return 'new' else: return 'old'
转载于:https://www.cnblogs.com/Eric-Young/p/6678762.html
本文介绍了在Django中如何进行日期的比较和操作,详细阐述了相关的方法和技巧,适用于Python开发者在处理日期字段时的参考。
34

被折叠的 条评论
为什么被折叠?



