You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kompass/jdav_web/mailer/models.py

31 lines
993 B
Python

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mass_mail
# Create your models here.
class Message(models.Model):
"""Represents a message that can be sent to some members"""
from_addr = models.EmailField(_('from email'))
subject = models.CharField(_('subject'), max_length=50)
content = models.TextField(_('content'))
to_group = models.ForeignKey('members.Group', verbose_name=_('to group'))
def __str__(self):
return self.subject
def submit(self):
"""Sends the mail to the specified group of members"""
data = [
(self.subject, self.content, self.from_addr, [member.email])
for member in self.to_group.member_set.all()
]
send_mass_mail(data)
class Meta:
verbose_name = _('message')
verbose_name_plural = _('messages')
permissions = (
("submit_mails", _("Can submit mails")),
)