models.py 1.81 KB
Newer Older
1
from django.db import models
2 3
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
okhin's avatar
okhin committed
4
from ckeditor.fields import RichTextField
5

6 7
from picampaign.organization.models import Organization
from picampaign.contact.models import Contact
8 9 10 11 12 13


class Campaign(models.Model):
    """Campaign model, describe what have to be achieved"""
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255)
okhin's avatar
okhin committed
14
    description = RichTextField(null=True)
15
    organization = models.ForeignKey(Organization, related_name='campaigns')
16 17
    start_date = models.DateField()
    end_date = models.DateField()
18
    phone_filter = models.CharField(max_length=20, null=True, blank=True)
19

20
    def __str__(self):
21
        return self.title
22 23

class Argumentary(models.Model):
24
    """Argumentary for a campaign"""
25
    id = models.AutoField(primary_key=True)
26
    campaign = models.ForeignKey(Campaign)
27 28
    title = models.CharField(max_length=255, verbose_name=_('title'), null=True, blank=True)
    text = RichTextField(null=True)
29

30 31 32 33
    class Meta:
        verbose_name = _("Argument")
        verbose_name_plural = _("Arguments")

34
    def __str__(self):
35 36
        args = {'title': self.campaign.title}
        return _('Argumentary for %(title)s') % args
37

38 39 40
class CampaignContact(models.Model):
    """List contact related to a campaign with a given weight"""
    id = models.AutoField(primary_key=True)
41 42
    campaign = models.ForeignKey(Campaign)
    contact = models.ForeignKey(Contact)
43
    weight = models.IntegerField(default=0)
44

okhin's avatar
okhin committed
45 46 47
    class Meta:
        unique_together = (("campaign", "contact"),)

48
    def __str__(self):
Aymeric Barantal's avatar
Aymeric Barantal committed
49 50
        args = {'contact': self.contact, 'title': self.campaign.title}
        return _('Contact %(contact)s on %(title)s') % args
51 52 53

    def all_groups(self):
        return [x.name for x in self.contact.groups.all()]