mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 11:31:07 -05:00
Implement historical tracking using django-pghistory; add middleware for context capture and update model architecture
This commit is contained in:
39
memory-bank/workflows/model-migrations.md
Normal file
39
memory-bank/workflows/model-migrations.md
Normal file
@@ -0,0 +1,39 @@
|
||||
## Model Migration Protocol for History Tracking
|
||||
|
||||
### Implementation Steps
|
||||
1. **Base Model Setup**
|
||||
```python
|
||||
# core/models.py
|
||||
import pghistory
|
||||
|
||||
class HistoricalModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@pghistory.track(pghistory.Snapshot())
|
||||
def save(self, *args, **kwargs):
|
||||
return super().save(*args, **kwargs)
|
||||
```
|
||||
|
||||
2. **Concrete Model Implementation**
|
||||
```python
|
||||
# parks/models.py
|
||||
class Park(HistoricalModel):
|
||||
@pghistory.track(
|
||||
pghistory.Snapshot('park.create'),
|
||||
pghistory.AfterUpdate('park.update'),
|
||||
pghistory.BeforeDelete('park.delete')
|
||||
)
|
||||
class Meta:
|
||||
# Existing model fields and configuration
|
||||
```
|
||||
|
||||
3. **Migration Generation**
|
||||
```bash
|
||||
./manage.py makemigrations --name add_pghistory_tracking
|
||||
```
|
||||
|
||||
### Quality Assurance
|
||||
1. Verify historical events table creation
|
||||
2. Test event triggering for CRUD operations
|
||||
3. Validate context metadata capture
|
||||
31
memory-bank/workflows/moderation.md
Normal file
31
memory-bank/workflows/moderation.md
Normal file
@@ -0,0 +1,31 @@
|
||||
## Updated Moderation Workflow with django-pghistory
|
||||
|
||||
### Submission Lifecycle
|
||||
1. **Change Proposal**
|
||||
- Creates `pending` pghistory event with metadata:
|
||||
```python
|
||||
pghistory.track(
|
||||
pghistory.Snapshot('submission.pending'),
|
||||
status='pending'
|
||||
)
|
||||
```
|
||||
2. **Approval Process**
|
||||
- Merges event into main history:
|
||||
```python
|
||||
event.pgh_label = 'approved_change'
|
||||
event.pgh_context['approver'] = request.user
|
||||
```
|
||||
3. **Rejection Handling**
|
||||
- Preserves event with rejection context:
|
||||
```python
|
||||
event.pgh_label = 'rejected_change'
|
||||
event.pgh_context['reason'] = rejection_reason
|
||||
```
|
||||
|
||||
### Moderation Admin Integration
|
||||
```python
|
||||
# moderation/admin.py
|
||||
@admin.register(pghistory.models.Event)
|
||||
class HistoryAdmin(admin.ModelAdmin):
|
||||
list_display = ('pgh_label', 'pgh_created_at', 'content_object')
|
||||
readonly_fields = ('pgh_data', 'pgh_context')
|
||||
Reference in New Issue
Block a user