import uuid import pghistory from django.db import models @pghistory.track() class Report(models.Model): """User-submitted reports for content moderation""" STATUS_CHOICES = [ ('pending', 'Pending Review'), ('reviewing', 'Under Review'), ('resolved', 'Resolved'), ('dismissed', 'Dismissed'), ] REPORT_TYPE_CHOICES = [ ('inappropriate', 'Inappropriate Content'), ('inaccurate', 'Inaccurate Information'), ('spam', 'Spam'), ('duplicate', 'Duplicate'), ('copyright', 'Copyright Violation'), ('other', 'Other'), ] id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) # What is being reported entity_type = models.CharField(max_length=50, db_index=True) entity_id = models.UUIDField(db_index=True) # Report details report_type = models.CharField(max_length=50, choices=REPORT_TYPE_CHOICES) description = models.TextField() status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending', db_index=True) # Reporter reported_by = models.ForeignKey('users.User', on_delete=models.CASCADE, related_name='reports_created') # Moderation reviewed_by = models.ForeignKey('users.User', null=True, blank=True, on_delete=models.SET_NULL, related_name='reports_reviewed') reviewed_at = models.DateTimeField(null=True, blank=True) resolution_notes = models.TextField(null=True, blank=True) # Timestamps created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: verbose_name = 'Report' verbose_name_plural = 'Reports' ordering = ['-created_at'] indexes = [ models.Index(fields=['entity_type', 'entity_id']), models.Index(fields=['status', '-created_at']), models.Index(fields=['reported_by', '-created_at']), ] def __str__(self): return f"{self.get_report_type_display()} - {self.entity_type} ({self.status})"