# Optional: custom error handlers
handler404 = 'myapp.views.custom_404'
handler500 = 'myapp.views.custom_500'
# In views.py
from django.contrib import admin
from django.utils.html import format_html
from .models import Post, Comment
class CommentInline(admin.TabularInline):
from django import template
from django.utils.safestring import mark_safe
import markdown
register = template.Library()
import time
import logging
logger = logging.getLogger(__name__)
INSTALLED_APPS += ['tenant_schemas']
DATABASE_ROUTERS = ['tenant_schemas.routers.TenantSyncRouter']
MIDDLEWARE = [
'tenant_schemas.middleware.TenantMiddleware',
from django.db.models import Q
from django.views.generic import ListView
from .models import Product
class ProductSearchView(ListView):
from django.db import transaction
from django.shortcuts import get_object_or_404
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from .models import Order, OrderItem, Product
from rest_framework import permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
import csv
from django.core.management.base import BaseCommand, CommandError
from products.models import Product, Category
class Command(BaseCommand):
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_user_model
User = get_user_model()
INSTALLED_APPS += ['corsheaders']
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # Must be before CommonMiddleware
'django.middleware.common.CommonMiddleware',
# ... other middleware
from django import template
from django.db.models import Count
from blog.models import Post, Tag
register = template.Library()