# 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'
from django.db.models import Count, Avg, Sum, Q, F
from django.views.generic import TemplateView
from products.models import Product, Order, OrderItem
class DashboardView(TemplateView):
from django.db import models
from django.utils import timezone
from datetime import date
class Person(models.Model):
import uuid
import logging
class RequestIDMiddleware:
def __init__(self, get_response):
import random
class PrimaryReplicaRouter:
"""Route reads to replicas, writes to primary."""
from django.conf import settings
from datetime import datetime
def site_settings(request):
"""Add site-wide settings to template context."""
from django.contrib import admin
from django.utils.html import format_html
from .models import Post, Comment
class CommentInline(admin.TabularInline):
from django.db.models import Q
from django.views.generic import ListView
from .models import Product
class ProductSearchView(ListView):
from django.core.exceptions import ValidationError
def validate_file_size(file):
"""Limit file size to 5MB."""
max_size_mb = 5