Refactor comments app to use mixins for comment functionality; update admin interfaces and add historical model fixes

This commit is contained in:
pacnpal
2025-02-08 16:33:55 -05:00
parent f000c492e8
commit 181f49a0f2
21 changed files with 548 additions and 280 deletions

View File

@@ -5,8 +5,11 @@ from django.contrib.contenttypes.models import ContentType
from django.core.validators import MinValueValidator, MaxValueValidator
from history_tracking.models import HistoricalModel, VersionBranch, ChangeSet
from history_tracking.signals import get_current_branch, ChangesetContextManager
from comments.mixins import CommentableMixin
from media.mixins import PhotoableModel
class Review(HistoricalModel):
class Review(HistoricalModel, CommentableMixin, PhotoableModel):
comments = GenericRelation('comments.CommentThread') # Centralized reference
# Generic relation to allow reviews on different types (rides, parks)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
@@ -41,17 +44,13 @@ class Review(HistoricalModel):
)
moderated_at = models.DateTimeField(null=True, blank=True)
# Comments
comments = GenericRelation('comments.CommentThread',
related_name='review_threads',
related_query_name='comments_thread'
)
class Meta:
ordering = ['-created_at']
indexes = [
models.Index(fields=['content_type', 'object_id']),
]
excluded_fields = ['comments'] # Exclude from historical tracking
def __str__(self):
return f"Review of {self.content_object} by {self.user.username}"
@@ -108,22 +107,6 @@ class Review(HistoricalModel):
return f"{base_url}#review-{self.pk}"
return reverse('reviews:review_detail', kwargs={'pk': self.pk})
class ReviewImage(models.Model):
review = models.ForeignKey(
Review,
on_delete=models.CASCADE,
related_name='images'
)
image = models.ImageField(upload_to='review_images/')
caption = models.CharField(max_length=200, blank=True)
order = models.PositiveIntegerField(default=0)
class Meta:
ordering = ['order']
def __str__(self):
return f"Image {self.order + 1} for {self.review}"
class ReviewLike(models.Model):
review = models.ForeignKey(
Review,