mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 17:31:09 -05:00
Refactor comments app to use mixins for comment functionality; update admin interfaces and add historical model fixes
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
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
|
||||
from reviews.mixins import ReviewableMixin
|
||||
|
||||
|
||||
# Shared choices that will be used by multiple models
|
||||
@@ -19,7 +22,8 @@ CATEGORY_CHOICES = [
|
||||
]
|
||||
|
||||
|
||||
class RideModel(HistoricalModel):
|
||||
class RideModel(HistoricalModel, CommentableMixin, PhotoableModel):
|
||||
comments = GenericRelation('comments.CommentThread') # Centralized reference
|
||||
"""
|
||||
Represents a specific model/type of ride that can be manufactured by different companies.
|
||||
For example: B&M Dive Coaster, Vekoma Boomerang, etc.
|
||||
@@ -41,14 +45,12 @@ class RideModel(HistoricalModel):
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
comments = GenericRelation('comments.CommentThread',
|
||||
related_name='ride_model_threads',
|
||||
related_query_name='comments_thread'
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
ordering = ['manufacturer', 'name']
|
||||
unique_together = ['manufacturer', 'name']
|
||||
excluded_fields = ['comments'] # Exclude from historical tracking
|
||||
def __str__(self) -> str:
|
||||
return self.name if not self.manufacturer else f"{self.manufacturer.name} {self.name}"
|
||||
|
||||
@@ -96,7 +98,8 @@ def get_absolute_url(self) -> str:
|
||||
|
||||
|
||||
|
||||
class Ride(HistoricalModel):
|
||||
class Ride(HistoricalModel, CommentableMixin, PhotoableModel, ReviewableMixin):
|
||||
comments = GenericRelation('comments.CommentThread') # Centralized reference
|
||||
STATUS_CHOICES = [
|
||||
('OPERATING', 'Operating'),
|
||||
('SBNO', 'Standing But Not Operating'),
|
||||
@@ -181,16 +184,11 @@ class Ride(HistoricalModel):
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
photos = GenericRelation('media.Photo')
|
||||
reviews = GenericRelation('reviews.Review')
|
||||
comments = GenericRelation('comments.CommentThread',
|
||||
related_name='ride_threads',
|
||||
related_query_name='comments_thread'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
unique_together = ['park', 'slug']
|
||||
excluded_fields = ['comments'] # Exclude from historical tracking
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} at {self.park.name}"
|
||||
|
||||
Reference in New Issue
Block a user