I'm attempting to use a Cron Job to update the number of days each record in my database has been "open" for(ie. the number of days between today and the created date). The logic I'm using is for the cron job to run every night at 23:00 and to update the days_open field (IntegerField) by F('days_open') + 1 each time the job runs.
I've set the run-time to once a minute for testing purposes. I've run "python manage.py runcrons "request_form_app.cron.DaysOpenCronJob" and " python manage.py runcrons --force" to force the jobs, and I receive no errors but the field is not updating on any of the records.
cron.py
from django_cron import CronJobBase, Schedule
from django.db.models import F
class DaysOpenCronJob(CronJobBase):
RUN_EVERY_MINS = 1
# RUN_AT_TIMES = ['23:00']
schedule = Schedule(run_at_times=RUN_EVERY_MINS)
code = 'request_form_app.cron.DaysOpenCronJob'
def update_days(self,*args,**kwargs):
data_request = Request.objects.all()
for record in data_request:
record.days_open = F('days_open') + 1
record.save(update_field=['days_open'])