mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 06:11:07 -05:00
2.1 KiB
2.1 KiB
Comment System Architecture Fix
Required Code Modifications
1. Central CommentThread Model (comments/models.py)
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
class CommentThread(models.Model):
"""Centralized comment threading system"""
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
indexes = [
models.Index(fields=["content_type", "object_id"]),
]
app_label = 'comments'
2. Model Reference Updates (Example for companies/models.py)
# In all affected models (companies, rides, parks, reviews):
from comments.models import CommentThread
class Company(models.Model):
# ... existing fields ...
comments = GenericRelation(CommentThread) # Updated reference
3. Historical Records Adjustment
# Historical model definitions:
class HistoricalCompany(HistoricalRecords):
comments = models.ForeignKey(
'comments.CommentThread', # Unified reference
on_delete=models.SET_NULL,
null=True,
blank=True
)
Migration Execution Plan
- Generate initial comment thread migration:
./manage.py makemigrations comments --name create_commentthread
- Create dependent migrations for each modified app:
for app in companies rides parks reviews; do
./manage.py makemigrations $app --name update_comment_references
done
- Migration dependency chain:
# In each app's migration file:
dependencies = [
('comments', '0001_create_commentthread'),
]
Validation Checklist
- Run full test suite:
uv test ./manage.py test - Execute system check:
uv run ./manage.py check --deploy - Verify database schema changes in migration files
- Confirm admin interface comment relationships