diff options
author | luxagraf <sng@luxagraf.net> | 2019-05-05 11:40:42 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-05-05 11:40:42 -0500 |
commit | a2891841fbf1e5660693a1f9109f2e6810224a3b (patch) | |
tree | be0aae73fe8f5e6271a76e8c5c6dc35b00f347a6 /app/django_comments/models.py | |
parent | bdc06f56d538358f1fa07d35afb5733c790e3ab2 (diff) |
Diffstat (limited to 'app/django_comments/models.py')
-rw-r--r-- | app/django_comments/models.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/app/django_comments/models.py b/app/django_comments/models.py new file mode 100644 index 0000000..ebf1bc5 --- /dev/null +++ b/app/django_comments/models.py @@ -0,0 +1,62 @@ +from django.conf import settings +from django.db import models +from django.utils import timezone +from django.utils.encoding import python_2_unicode_compatible +from django.utils.translation import ugettext_lazy as _ + +from .abstracts import ( + COMMENT_MAX_LENGTH, BaseCommentAbstractModel, CommentAbstractModel, +) + + +class Comment(CommentAbstractModel): + class Meta(CommentAbstractModel.Meta): + db_table = "django_comments" + + +@python_2_unicode_compatible +class CommentFlag(models.Model): + """ + Records a flag on a comment. This is intentionally flexible; right now, a + flag could be: + + * A "removal suggestion" -- where a user suggests a comment for (potential) removal. + + * A "moderator deletion" -- used when a moderator deletes a comment. + + You can (ab)use this model to add other flags, if needed. However, by + design users are only allowed to flag a comment with a given flag once; + if you want rating look elsewhere. + """ + user = models.ForeignKey( + settings.AUTH_USER_MODEL, verbose_name=_('user'), related_name="comment_flags", + on_delete=models.CASCADE, + ) + comment = models.ForeignKey( + # Translators: 'comment' is a noun here. + Comment, verbose_name=_('comment'), related_name="flags", on_delete=models.CASCADE, + ) + # Translators: 'flag' is a noun here. + flag = models.CharField(_('flag'), max_length=30, db_index=True) + flag_date = models.DateTimeField(_('date'), default=None) + + # Constants for flag types + SUGGEST_REMOVAL = "removal suggestion" + MODERATOR_DELETION = "moderator deletion" + MODERATOR_APPROVAL = "moderator approval" + + class Meta: + db_table = 'django_comment_flags' + unique_together = [('user', 'comment', 'flag')] + verbose_name = _('comment flag') + verbose_name_plural = _('comment flags') + + def __str__(self): + return "%s flag of comment ID %s by %s" % ( + self.flag, self.comment_id, self.user.get_username() + ) + + def save(self, *args, **kwargs): + if self.flag_date is None: + self.flag_date = timezone.now() + super(CommentFlag, self).save(*args, **kwargs) |