mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:31:09 -05:00
75 lines
2.1 KiB
Markdown
75 lines
2.1 KiB
Markdown
# Comment System Architecture Fix
|
|
|
|
## Required Code Modifications
|
|
|
|
### 1. Central CommentThread Model (comments/models.py)
|
|
```python
|
|
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)
|
|
```python
|
|
# 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
|
|
```python
|
|
# 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
|
|
|
|
1. Generate initial comment thread migration:
|
|
```bash
|
|
./manage.py makemigrations comments --name create_commentthread
|
|
```
|
|
|
|
2. Create dependent migrations for each modified app:
|
|
```bash
|
|
for app in companies rides parks reviews; do
|
|
./manage.py makemigrations $app --name update_comment_references
|
|
done
|
|
```
|
|
|
|
3. Migration dependency chain:
|
|
```python
|
|
# 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
|