Add Character.involved property.
[matthijs/projects/xerxes.git] / influences / models.py
index 8478ecc0f728e493f6122797939d9a46300d706b..c513c1a5c307e3f29b9365c12252fac42e8acc78 100644 (file)
@@ -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):
@@ -47,6 +48,7 @@ class Influence(models.Model):
     
     initiator   = models.ForeignKey(Character, verbose_name = _("Initiator"), related_name='initiated_influences')
     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"))
@@ -92,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")