mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-23 08:31:07 -05:00
feat: Refactor rides app with unique constraints, mixins, and enhanced documentation
- Added migration to convert unique_together constraints to UniqueConstraint for RideModel. - Introduced RideFormMixin for handling entity suggestions in ride forms. - Created comprehensive code standards documentation outlining formatting, docstring requirements, complexity guidelines, and testing requirements. - Established error handling guidelines with a structured exception hierarchy and best practices for API and view error handling. - Documented view pattern guidelines, emphasizing the use of CBVs, FBVs, and ViewSets with examples. - Implemented a benchmarking script for query performance analysis and optimization. - Developed security documentation detailing measures, configurations, and a security checklist. - Compiled a database optimization guide covering indexing strategies, query optimization patterns, and computed fields.
This commit is contained in:
@@ -7,6 +7,7 @@ across all models using django-fsm-log.
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Count, Avg, F
|
||||
from django.db.models.functions import TruncDate, ExtractHour
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from django_fsm_log.models import StateLog
|
||||
@@ -148,9 +149,10 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f" System-initiated: {system_count} ({(system_count/total_transitions)*100:.1f}%)")
|
||||
|
||||
# Daily transition volume
|
||||
# Security: Using Django ORM functions instead of raw SQL .extra() to prevent SQL injection
|
||||
self.stdout.write(self.style.SUCCESS('\n--- Daily Transition Volume ---'))
|
||||
daily_stats = (
|
||||
queryset.extra(select={'day': 'date(timestamp)'})
|
||||
queryset.annotate(day=TruncDate('timestamp'))
|
||||
.values('day')
|
||||
.annotate(count=Count('id'))
|
||||
.order_by('-day')[:7]
|
||||
@@ -162,9 +164,10 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f" {date}: {count} transitions")
|
||||
|
||||
# Busiest hours
|
||||
# Security: Using Django ORM functions instead of raw SQL .extra() to prevent SQL injection
|
||||
self.stdout.write(self.style.SUCCESS('\n--- Busiest Hours (UTC) ---'))
|
||||
hourly_stats = (
|
||||
queryset.extra(select={'hour': 'extract(hour from timestamp)'})
|
||||
queryset.annotate(hour=ExtractHour('timestamp'))
|
||||
.values('hour')
|
||||
.annotate(count=Count('id'))
|
||||
.order_by('-count')[:5]
|
||||
|
||||
Reference in New Issue
Block a user