class Product(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField(blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
cost = models.DecimalField(max_digits=10, decimal_places=2)
margin = models.DecimalField(max_digits=5, decimal_places=2, blank=True)
from django.urls import path
from . import views
app_name = 'blog'
urlpatterns = [
import graphene
from graphene_django import DjangoObjectType
from blog.models import Post, Comment
class PostType(DjangoObjectType):
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 rest_framework import permissions
class IsOwner(permissions.BasePermission):
"""Allow only object owner to access."""
from django.db import models
from django.utils.text import slugify
class Article(models.Model):
title = models.CharField(max_length=200)
import logging
import time
logger = logging.getLogger(__name__)
INSTALLED_APPS += [
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
from django.db import models
from django.utils import timezone
class PostQuerySet(models.QuerySet):
def published(self):
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.models import F, Window
from django.db.models.functions import RowNumber, Rank, DenseRank
from products.models import Sale
def get_sales_with_ranking():
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
"""Extended user model with additional fields."""