sendplannednewsletters.py 471 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from django.core.management.base import BaseCommand
from django.utils import timezone

from newsletters import emails
from newsletters.models import Newsletter


class Command(BaseCommand):

    def handle(self, *args, **options):
        newsletters = Newsletter.objects.filter(
            send_date__lte=timezone.now(),
            sent=False
        )
        for n in newsletters:
            emails.send_newsletter(n)
17
18
            n.sent = True
            n.save()