diff mbox series

[1/9] models: Add Note model

Message ID 20240313065642.385843-1-andrepapoti@gmail.com
State New
Headers show
Series [1/9] models: Add Note model | expand

Commit Message

andrepapoti March 13, 2024, 6:56 a.m. UTC
Signed-off-by: andrepapoti <andrepapoti@gmail.com>
---
 patchwork/models.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index 9a619bc..b73a95a 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -823,6 +823,30 @@  class PatchComment(EmailMixin, models.Model):
         ]
 
 
+class Note(models.Model):
+    patch = models.ForeignKey(
+        Patch,
+        related_name='note',
+        related_query_name='note',
+        on_delete=models.CASCADE,
+    )
+    submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
+    last_modified = models.DateTimeField(default=tz_utils.now)
+    content = models.TextField(null=False, blank=True)
+    maintainer_only = models.BooleanField(default=True)
+    __original_content = None
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.__original_content = self.content
+
+    def save(self, *args, **kwargs):
+        if self.content != self.__original_content:
+            self.last_modified = tz_utils.now().isoformat()
+            self.__original_content = self.content
+        super(Note, self).save(*args, **kwargs)
+
+
 class Series(FilenameMixin, models.Model):
     """A collection of patches."""