使用 model 的 instance method 进行比赛状态的判断
This commit is contained in:
1 parent
1c37c4bfb6
commit
76b28f2da2
3 files changed
+24
-7
No files matched your search
@@ -4,19 +4,23 @@ from django.utils.timezone import now
|
||||
|
||||
|
||||
def get_contest_status(contest):
|
||||
if contest.start_time > now():
|
||||
status = contest.status
|
||||
if status == 1:
|
||||
return "没有开始"
|
||||
if contest.end_time < now():
|
||||
elif status == -1:
|
||||
return "已经结束"
|
||||
return "正在进行"
|
||||
else:
|
||||
return "正在进行"
|
||||
|
||||
|
||||
def get_contest_status_color(contest):
|
||||
if contest.start_time > now():
|
||||
status = contest.status
|
||||
if status == 1:
|
||||
return "info"
|
||||
if contest.end_time < now():
|
||||
elif status == -1:
|
||||
return "warning"
|
||||
return "success"
|
||||
else:
|
||||
return "success"
|
||||
|
||||
|
||||
from django import template
|
||||
|
||||
Reference in new issue
Block a user