-
Notifications
You must be signed in to change notification settings - Fork 0
/
routine.py
33 lines (26 loc) · 938 Bytes
/
routine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
import django
django.setup()
from challenge.models import *
import datetime
#날짜바뀔때 실행하는 EnrollmentDate객체 만드는 함수
def change_challenge_status():
today = datetime.date.today()
for C in Challenge.objects.all():
if C.start_date > today:
C.status = 0
C.save()
elif C.end_date < today:
C.status = 2
C.save()
else:
C.status = 1
C.save()
def make_enrollment_date():
for E in Enrollment.objects.all().filter(challenge__status=1):
if not(EnrollmentDate.objects.filter(enrollment=E, date=datetime.date.today()).exists()):
new_ed = EnrollmentDate(enrollment=E, date=datetime.date.today())
new_ed.save() #오늘의 날짜로 EnrollmentDate 생성
change_challenge_status()
make_enrollment_date()