我很难尝试根据guide设置Django cron计划。
settings.py:
INSTALLED_APPS = [
'django_cron',
]
CRON_CLASSES = [
"eventscalendar.cron.MyCronJob",
]
eventscalendar应用程序内的cron.py:
from django_cron import CronJobBase, Schedule
from eventscalendar.models import Subtask
import random
class MyCronJob(CronJobBase):
frequency = 1
schedule = Schedule(run_every_mins=frequency)
code = 'eventscalendar.my_cron_job'
def do(self):
number = random.randint(1, 100)
# save data to database
add_records = Subtask(subtask_name='test' + str(number), subtask_description='test' + str(number))
add_records.save()
问题:
谢谢您的时间。