X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=influences%2Fmodels.py;h=c513c1a5c307e3f29b9365c12252fac42e8acc78;hb=fe2d9095c7819fbe98ae1448a8aba1094090cdd8;hp=9fd77ef846954815a32c9a2108bc23a5ee9f16cf;hpb=3ebe90d3cef8c2136c17a1b3426e7989f2379427;p=matthijs%2Fprojects%2Fxerxes.git diff --git a/influences/models.py b/influences/models.py index 9fd77ef..c513c1a 100644 --- a/influences/models.py +++ b/influences/models.py @@ -5,6 +5,7 @@ from django.utils.text import normalize_newlines from django.utils.translation import ugettext_lazy as _ from threadedcomments.models import ThreadedComment from xerxes.tools.text import rewrap +from string import strip # Create your models here. class Character(models.Model): @@ -22,6 +23,7 @@ class Character(models.Model): name = models.CharField(max_length=255, verbose_name = _("Name")) status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='N', verbose_name = _("Status")) player = models.ForeignKey(User, verbose_name = _("Player")) + contacts = models.ManyToManyField('self') type = models.CharField(max_length=2, choices=TYPE_CHOICES, verbose_name=_("Type")) def __unicode__(self): @@ -45,7 +47,8 @@ class Influence(models.Model): modified = models.DateField(auto_now=1, verbose_name = _("Modification time")) initiator = models.ForeignKey(Character, verbose_name = _("Initiator"), related_name='initiated_influences') - contact = models.CharField(max_length=255, verbose_name = _("Contact Name")) + other_contacts = models.CharField(max_length=255, blank = True, verbose_name = _("Other Contacts")) + other_characters = models.ManyToManyField(Character, blank = True, verbose_name = _("Involved characters"), related_name='influences_involved_in') summary = models.CharField(max_length=255, verbose_name = _("Summary")) description = models.TextField(verbose_name = _("Description")) todo = models.TextField(verbose_name = _("Todo")) @@ -91,6 +94,14 @@ class Influence(models.Model): prefix=prefix) return comments + @property + def involved(self): + """ Returns the Characters and contacts (strings) involved """ + chars = list(self.other_characters.all()) + if (self.other_contacts): + chars.extend(map(strip,self.other_contacts.split(','))) + return chars + class Meta: verbose_name = _("Influence") verbose_name_plural = _("Influences")