moviewyrm/bookwyrm/models/report.py

38 lines
1 KiB
Python
Raw Normal View History

2021-03-09 01:16:59 +00:00
""" flagged for moderation """
from django.db import models
2021-03-09 02:36:34 +00:00
from django.db.models import F, Q
2021-03-09 01:16:59 +00:00
from .base_model import BookWyrmModel
class Report(BookWyrmModel):
2021-04-26 16:15:42 +00:00
"""reported status or user"""
2021-03-09 01:16:59 +00:00
reporter = models.ForeignKey(
"User", related_name="reporter", on_delete=models.PROTECT
)
note = models.TextField(null=True, blank=True)
user = models.ForeignKey("User", on_delete=models.PROTECT)
statuses = models.ManyToManyField("Status", blank=True)
2021-03-09 01:16:59 +00:00
resolved = models.BooleanField(default=False)
2021-03-09 02:36:34 +00:00
class Meta:
2021-04-26 16:15:42 +00:00
"""don't let users report themselves"""
2021-03-09 20:57:38 +00:00
2021-03-09 02:36:34 +00:00
constraints = [
2021-03-09 20:57:38 +00:00
models.CheckConstraint(check=~Q(reporter=F("user")), name="self_report")
2021-03-09 02:36:34 +00:00
]
2021-03-12 01:38:21 +00:00
ordering = ("-created_date",)
2021-03-09 01:16:59 +00:00
2021-03-09 20:57:38 +00:00
2021-03-09 01:16:59 +00:00
class ReportComment(BookWyrmModel):
2021-04-26 16:15:42 +00:00
"""updates on a report"""
2021-03-09 01:16:59 +00:00
user = models.ForeignKey("User", on_delete=models.PROTECT)
note = models.TextField()
report = models.ForeignKey(Report, on_delete=models.PROTECT)
2021-03-12 23:56:54 +00:00
class Meta:
2021-04-26 16:15:42 +00:00
"""sort comments"""
2021-03-12 23:56:54 +00:00
ordering = ("-created_date",)