models.py 1.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.db import models

from members.models import Member
from committees.models import Committee


class MailingList(models.Model):
    name = models.EmailField()
    prefix = models.CharField(max_length=200)
    archived = models.BooleanField(default=True)
    moderated = models.BooleanField(default=False)
    members = models.ManyToManyField(Member, blank=True)
    committees = models.ManyToManyField(Committee, blank=True)

    def all_addresses(self):
        for member in self.members.all():
            yield member.email

        for committee in self.committees.all().prefetch_related("members"):
            for member in committee.members.all():
                yield member.email

        for address in self.addresses.all():
            yield address

    def __str__(self):
        return self.name


class VerbatimAddress(models.Model):
    address = models.EmailField()
    mailinglist = models.ForeignKey(MailingList, related_name='addresses')


class ListAlias(models.Model):
    alias = models.EmailField()
    mailinglist = models.ForeignKey(MailingList, related_name='aliasses')