Last active
March 1, 2016 21:53
-
-
Save particledecay/2351119ebffd627610a9 to your computer and use it in GitHub Desktop.
[Django] Custom management command to check for all events starting in an arbitrary number of days, and send event reminder emails for them (run from a cron job as follows for 10-day, 3-day, and 1-day checks: 0 2 * * * /virtualenvs/foo/bin/python /projects/foo/foo/manage.py check_reminders 10 3 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
from django.core.management.base import BaseCommand, CommandError | |
from foo.firms.models import Event | |
class Command(BaseCommand): | |
args = '<days days ...>' | |
help = "Check for any Events that start in a given number of days, and execute send_reminder() on them" | |
def handle(self, *args, **kwargs): | |
if args: | |
days = args | |
else: | |
days = [10] | |
for day in days: | |
day = int(day) | |
dt = datetime.now().date() + timedelta(days=day) | |
upcoming_events = Event.objects.filter(event_start_date__year=dt.year, event_start_date__month=dt.month, event_start_date__day=dt.day) | |
[event.send_reminder(day) for event in upcoming_events] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment