from django.db import models
from django.utils import timezone
class SoftDeleteManager(models.Manager):
def get_queryset(self):
from datetime import timedelta
INSTALLED_APPS += ['rest_framework_simplejwt']
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from .models import Post
from .forms import PostForm
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.conf import settings
def send_welcome_email(user):
from django.db import connection
from blog.models import Post
def get_top_authors(limit=10):
"""Get authors with most published posts using raw SQL."""
from django.db import models
from django.contrib.postgres.indexes import GinIndex
class Post(models.Model):
title = models.CharField(max_length=200, db_index=True)
# Debug Toolbar setup
INSTALLED_APPS += ['debug_toolbar']
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
] + MIDDLEWARE
import re
class APIVersionMiddleware:
"""Extract API version from request and add to request object."""
# Find products with specific spec value
products = Product.objects.filter(specs__weight__gte=100)
# Check if JSON key exists
products = Product.objects.filter(specs__has_key='color')
from django.db import models
from django.utils import timezone
class Event(models.Model):
name = models.CharField(max_length=200)
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent.parent
SECRET_KEY = os.environ.get('SECRET_KEY', 'dev-secret-key-change-in-production')
from rest_framework.throttling import UserRateThrottle
class BurstRateThrottle(UserRateThrottle):
"""Allow short bursts of requests."""
scope = 'burst'