0

I am stuck in one problem and i want to notify current logged user for it's insurance will be expired within 5 days ago.

class Vehicle(models.Model):
vehicle_no = models.CharField(max_length=100, blank=False, null=False)
chasis_no = models.CharField(max_length=100, blank=False, null=False, unique=True)
make = models.CharField(max_length=100, blank=False, null=False)
insurance_no = models.CharField(max_length=100, blank=False, null=False)
insurance_date = models.DateField(blank=False, null=False)
insurance_expiry_date = models.DateField(blank=False, null=False)

Please help me to find exact solution

1 Answers1

0

You need something called cron or cronjob. Very easy to use is django-crontab.

Install:

$ pip install django-crontab

your_app/cron.py:

def my_scheduled_job():
  # check every Vehicle's insurance if is exactly 5 days from expiring

settings.py:

INSTALLED_APPS = (
    'django_crontab',
    ...
)

# it will execute this function at 4:59 every single day
CRONJOBS = [
    ('59 4 * * *', 'your_app.cron.my_scheduled_job')
]

Then activate / control / remove with commands:

$ python manage.py crontab add
$ python manage.py crontab show
$ python manage.py crontab remove

More details get on pypi.org.

NixonSparrow
  • 6,130
  • 1
  • 6
  • 18