diff messages/models.py @ 810:4a4fa174a0ec

Private message refactor: adding ability to report PM's. See also Bitbucket issue #57.
author Brian Neal <bgneal@gmail.com>
date Sat, 06 Sep 2014 16:58:08 -0500
parents ee87ea74d46b
children 82f1f6f905eb
line wrap: on
line diff
--- a/messages/models.py	Mon Sep 01 17:05:30 2014 -0500
+++ b/messages/models.py	Sat Sep 06 16:58:08 2014 -0500
@@ -101,3 +101,22 @@
         verbose_name_plural = "Options"
 
 
+class Flag(models.Model):
+    """The Flag model is used to represent when a receiver of a private message
+    has flagged the message for spam or abuse.
+
+    """
+    message = models.OneToOneField(Message)
+    flag_date = models.DateTimeField()
+    comments = models.TextField(blank=True)
+
+    def __unicode__(self):
+        msg = self.message
+        return "{} has flagged a PM from {}".format(msg.receiver.username,
+                msg.sender.username)
+
+    def save(self, *args, **kwargs):
+        if not self.id:
+            self.flag_date = datetime.datetime.now()
+        super(Flag, self).save(*args, **kwargs)
+