Skip to content

Commit 3a2abfd

Browse files
committed
models: Add Note model
Signed-off-by: andrepapoti <[email protected]>
1 parent 7494873 commit 3a2abfd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

patchwork/models.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def validate_regex_compiles(regex_string):
3333
raise ValidationError('Invalid regular expression entered!')
3434

3535

36+
class TimestampMixin(models.Model):
37+
created_at = models.DateTimeField(default=tz_utils.now)
38+
updated_at = models.DateTimeField(default=tz_utils.now)
39+
40+
def update_timestamp(self):
41+
self.updated_at = tz_utils.now().isoformat()
42+
43+
3644
class Person(models.Model):
3745
# properties
3846

@@ -823,6 +831,29 @@ class Meta:
823831
]
824832

825833

834+
class Note(TimestampMixin, models.Model):
835+
patch = models.ForeignKey(
836+
Patch,
837+
related_name='note',
838+
related_query_name='note',
839+
on_delete=models.CASCADE,
840+
)
841+
submitter = models.ForeignKey(User, on_delete=models.CASCADE)
842+
content = models.TextField(null=False, blank=True)
843+
maintainer_only = models.BooleanField(default=True)
844+
__original_content = None
845+
846+
def __init__(self, *args, **kwargs):
847+
super().__init__(*args, **kwargs)
848+
self.__original_content = self.content
849+
850+
def save(self, *args, **kwargs):
851+
if self.content != self.__original_content:
852+
self.update_timestamp()
853+
self.__original_content = self.content
854+
super().save(*args, **kwargs)
855+
856+
826857
class Series(FilenameMixin, models.Model):
827858
"""A collection of patches."""
828859

0 commit comments

Comments
 (0)