from django.db import models
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
sns.set_theme(style='whitegrid', palette='deep', context='talk')
plt.rcParams.update({
import abc
from typing import IO
class Exporter(abc.ABC):
name: str = ""
from django.db import migrations
def populate_slugs(apps, schema_editor):
"""Generate slugs for existing posts."""
Post = apps.get_model('blog', 'Post')
import random
class ReadWriteRouter:
"""Route reads to replicas, writes to primary."""
from blog.models import Post
# Load only specific fields
posts = Post.objects.only('id', 'title', 'published_at')
for post in posts:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydb',
'USER': 'myuser',
'PASSWORD': 'mypassword',
# Debug Toolbar setup
INSTALLED_APPS += ['debug_toolbar']
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
] + MIDDLEWARE
from rest_framework.pagination import PageNumberPagination, CursorPagination
class StandardResultsSetPagination(PageNumberPagination):
page_size = 25
page_size_query_param = 'page_size'
# Session configuration
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
SESSION_CACHE_ALIAS = 'default'
SESSION_COOKIE_AGE = 1209600 # 2 weeks in seconds
SESSION_COOKIE_SECURE = True # HTTPS only
SESSION_COOKIE_HTTPONLY = True # No JavaScript access
from django.db import models
from django.utils import timezone
class Event(models.Model):
name = models.CharField(max_length=200)
from rest_framework.throttling import UserRateThrottle
class BurstRateThrottle(UserRateThrottle):
"""Allow short bursts of requests."""
scope = 'burst'