class event_archive(models.Model):
event_id = models.AutoField(primary_key=True)
date_submitted = models.DateTimeField()
event_start_time = models.DateTimeField()
event_end_time = models.DateTimeField()
event_closed = models.BooleanField()
我想这样做:这是伪代码:
event = event_archive.objects.all()
for e in event:
if event_start_time > datetime_now()
print "upcoming";
elif event_start_time < datetime_now() < event_end_time
print "now";
elif event_end_time < datetime_now() < **24 hours passed the event ends**
print "%d hours ago",%hour;
elif event_end_time < datetime_now() > **24 hours passed the event ends** and event_end_time < datetime_now() < **48 hours passed the event ends**
print "yesterday";
else
print "recorded"
endif;
endfor;
**我在编程和python方面非常新。请不要在意我是否提出了非常愚蠢的问题或者没有明确地提出问题。在粗线条中我不知道应该使用什么?
我需要帮助来编写我的django视图功能..请帮助...
答案 0 :(得分:1)
import datetime
if some_datetime > datetime.datetime.now() + datetime.timedelta(days=10):
return "some_date is greater than the current datetime plus 10 days"
请参阅timedelta doc:http://docs.python.org/library/datetime.html#datetime.timedelta
答案 1 :(得分:1)
答案 2 :(得分:0)
from datetime import datetime
datetime_now = datetime.now()
'datetime_now'变量现在具有当前时间。
使用此变量与事件开始时间进行比较并打印或为该条件执行相关操作。
例如:
if event_start_time > datetime_now:
print "upcoming"