generated from JustScreaMy/ProjectTemplate
Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
![]() |
24254b65e0 |
16 changed files with 21 additions and 215 deletions
|
@ -31,29 +31,27 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||||
SECRET_KEY = env.str('SECRET_KEY', 'django-insecure-x&7qy$na7*@u_4(izkfaz2yiea9+t(nf&#p9cnlq6x)_)jkacf')
|
SECRET_KEY = env.str('SECRET_KEY', 'django-insecure-x&7qy$na7*@u_4(izkfaz2yiea9+t(nf&#p9cnlq6x)_)jkacf')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = False
|
||||||
DEBUG_TOOLBAR = True
|
|
||||||
DEBUG_TOOLBAR_CONFIG = {
|
DEBUG_TOOLBAR_CONFIG = {
|
||||||
"INTERCEPT_REDIRECTS": False,
|
"SHOW_TOOLBAR_CALLBACK": lambda request: False,
|
||||||
"SHOW_TOOLBAR_CALLBACK": lambda request: True,
|
|
||||||
"IS_RUNNING_TESTS": False,
|
"IS_RUNNING_TESTS": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_TOOLBAR_PANELS = [
|
DEBUG_TOOLBAR_PANELS = [
|
||||||
# 'debug_toolbar.panels.history.HistoryPanel',
|
'debug_toolbar.panels.history.HistoryPanel',
|
||||||
# 'debug_toolbar.panels.versions.VersionsPanel',
|
'debug_toolbar.panels.versions.VersionsPanel',
|
||||||
'debug_toolbar.panels.timer.TimerPanel',
|
'debug_toolbar.panels.timer.TimerPanel',
|
||||||
# 'debug_toolbar.panels.settings.SettingsPanel',
|
'debug_toolbar.panels.settings.SettingsPanel',
|
||||||
# 'debug_toolbar.panels.headers.HeadersPanel',
|
'debug_toolbar.panels.headers.HeadersPanel',
|
||||||
# 'debug_toolbar.panels.request.RequestPanel',
|
'debug_toolbar.panels.request.RequestPanel',
|
||||||
'debug_toolbar.panels.sql.SQLPanel',
|
'debug_toolbar.panels.sql.SQLPanel',
|
||||||
# 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
|
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
|
||||||
# 'debug_toolbar.panels.templates.TemplatesPanel',
|
'debug_toolbar.panels.templates.TemplatesPanel',
|
||||||
# 'debug_toolbar.panels.alerts.AlertsPanel',
|
'debug_toolbar.panels.alerts.AlertsPanel',
|
||||||
# 'debug_toolbar.panels.cache.CachePanel',
|
'debug_toolbar.panels.cache.CachePanel',
|
||||||
# 'debug_toolbar.panels.signals.SignalsPanel',
|
'debug_toolbar.panels.signals.SignalsPanel',
|
||||||
# 'debug_toolbar.panels.redirects.RedirectsPanel',
|
'debug_toolbar.panels.redirects.RedirectsPanel',
|
||||||
# 'debug_toolbar.panels.profiling.ProfilingPanel',
|
'debug_toolbar.panels.profiling.ProfilingPanel',
|
||||||
]
|
]
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
|
@ -79,7 +77,6 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'tko.apps.TkoConfig',
|
'tko.apps.TkoConfig',
|
||||||
'shop.apps.ShopConfig',
|
|
||||||
'debug_toolbar',
|
'debug_toolbar',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'post_office',
|
'post_office',
|
||||||
|
|
|
@ -15,7 +15,7 @@ Including another URLconf
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path
|
||||||
from debug_toolbar.toolbar import debug_toolbar_urls
|
from debug_toolbar.toolbar import debug_toolbar_urls
|
||||||
|
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
|
@ -25,7 +25,6 @@ from tko.views import ContactView, NewArticleListView, AllArticleListView, Event
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('shop/', include("shop.urls")),
|
|
||||||
path('create-contact/', ContactView.as_view(), name='create-contact'),
|
path('create-contact/', ContactView.as_view(), name='create-contact'),
|
||||||
path('load-articles/', NewArticleListView.as_view(), name='load-articles'),
|
path('load-articles/', NewArticleListView.as_view(), name='load-articles'),
|
||||||
path('load-all-articles/', AllArticleListView.as_view(), name='load-all-articles'),
|
path('load-all-articles/', AllArticleListView.as_view(), name='load-all-articles'),
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
from shop import models
|
|
||||||
from shop.models import OrderProduct
|
|
||||||
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
@admin.register(models.Product)
|
|
||||||
class ProductAdmin(admin.ModelAdmin):
|
|
||||||
list_display = ["name", "price", "count"]
|
|
||||||
|
|
||||||
|
|
||||||
class OrderProductInline(admin.TabularInline):
|
|
||||||
model = OrderProduct
|
|
||||||
extra = 1
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Order)
|
|
||||||
class OrderAdmin(admin.ModelAdmin):
|
|
||||||
list_display = ["customer_name", "created"]
|
|
||||||
inlines = [OrderProductInline]
|
|
|
@ -1,6 +0,0 @@
|
||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class ShopConfig(AppConfig):
|
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = 'shop'
|
|
|
@ -1,12 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
PRODUCTS = [
|
|
||||||
{
|
|
||||||
"name": "Sušenka",
|
|
||||||
"price": 10,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Caprison",
|
|
||||||
"price": 15,
|
|
||||||
}
|
|
||||||
]
|
|
|
@ -1,40 +0,0 @@
|
||||||
# Generated by Django 5.1.5 on 2025-06-05 19:20
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Order',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('customer_name', models.CharField(max_length=100)),
|
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Product',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('name', models.CharField(max_length=100)),
|
|
||||||
('price', models.DecimalField(decimal_places=2, max_digits=10)),
|
|
||||||
('count', models.IntegerField()),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='OrderProduct',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='products', to='shop.order')),
|
|
||||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='shop.product')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,38 +0,0 @@
|
||||||
from django.db import models
|
|
||||||
|
|
||||||
|
|
||||||
class Order(models.Model):
|
|
||||||
customer_name = models.CharField(max_length=100)
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def get_total_price(self):
|
|
||||||
return sum(self.products.price)
|
|
||||||
|
|
||||||
def get_qr_code(self):
|
|
||||||
return self.customer_name
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"Order from {self.customer_name}, {self.created}"
|
|
||||||
|
|
||||||
|
|
||||||
class Product(models.Model):
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
price = models.DecimalField(decimal_places=2, max_digits=10)
|
|
||||||
count = models.IntegerField()
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.name}, {self.price} Kč ({self.count} pcs)"
|
|
||||||
|
|
||||||
|
|
||||||
class OrderProduct(models.Model):
|
|
||||||
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name='products')
|
|
||||||
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
|
||||||
count = models.PositiveIntegerField()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def price(self):
|
|
||||||
return self.product.price * self.count
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.product.name}, {self.count} pcs, each for {self.product.price} Kč"
|
|
|
@ -1,23 +0,0 @@
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from shop.models import Product, OrderProduct, Order
|
|
||||||
|
|
||||||
|
|
||||||
class ProductSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Product
|
|
||||||
fields = ["name", "price"]
|
|
||||||
|
|
||||||
|
|
||||||
class OrderProductSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = OrderProduct
|
|
||||||
fields = ["product", "count"]
|
|
||||||
|
|
||||||
|
|
||||||
class OrderSerializer(serializers.ModelSerializer):
|
|
||||||
products = OrderProductSerializer(many=True, read_only=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Order
|
|
||||||
fields = ["customer_name", "created", "products"]
|
|
|
@ -1,3 +0,0 @@
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
|
@ -1,24 +0,0 @@
|
||||||
"""
|
|
||||||
URL configuration.
|
|
||||||
|
|
||||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
||||||
https://docs.djangoproject.com/en/5.1/topics/http/urls/
|
|
||||||
Examples:
|
|
||||||
Function views
|
|
||||||
1. Add an import: from my_app import views
|
|
||||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
|
||||||
Class-based views
|
|
||||||
1. Add an import: from other_app.views import Home
|
|
||||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
|
||||||
Including another URLconf
|
|
||||||
1. Import the include() function: from django.urls import include, path
|
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
|
||||||
"""
|
|
||||||
from django.urls import path
|
|
||||||
|
|
||||||
from shop.views import LoadProductsView, CreateOrderView
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path('load-products/', LoadProductsView.as_view(), name='load-products'),
|
|
||||||
path('create-order/', CreateOrderView.as_view(), name='create-order'),
|
|
||||||
]
|
|
|
@ -1,21 +0,0 @@
|
||||||
from django.shortcuts import render
|
|
||||||
from rest_framework.generics import ListAPIView, CreateAPIView
|
|
||||||
|
|
||||||
from shop.serializers import ProductSerializer, OrderSerializer
|
|
||||||
|
|
||||||
from shop.models import Product
|
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
|
|
||||||
class LoadProductsView(ListAPIView):
|
|
||||||
serializer_class = ProductSerializer
|
|
||||||
template_name = 'shop/shop.html'
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
return Product.objects.all()
|
|
||||||
|
|
||||||
|
|
||||||
class CreateOrderView(CreateAPIView):
|
|
||||||
serializer_class = OrderSerializer
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ class ArticleListSerializer(serializers.ModelSerializer):
|
||||||
return obj.date.strftime("%-d. %-m. %Y")
|
return obj.date.strftime("%-d. %-m. %Y")
|
||||||
|
|
||||||
def get_image(self, obj):
|
def get_image(self, obj):
|
||||||
main_image = obj.images.order_by("main").first()
|
main_image = next(iter(obj.images.all()), None)
|
||||||
|
|
||||||
if main_image:
|
if main_image:
|
||||||
return ArticleImageSerializer(main_image, context=self.context).data
|
return ArticleImageSerializer(main_image, context=self.context).data
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db.models import Q
|
from django.db.models import Q, Prefetch
|
||||||
|
|
||||||
from post_office import mail
|
from post_office import mail
|
||||||
|
|
||||||
|
@ -46,7 +46,9 @@ class AllArticleListView(ListAPIView):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Article.objects.filter(
|
return Article.objects.filter(
|
||||||
Q(active_to__gte=timezone.now()) | Q(active_to__isnull=True)
|
Q(active_to__gte=timezone.now()) | Q(active_to__isnull=True)
|
||||||
).order_by('-date')
|
).order_by('-date').prefetch_related(
|
||||||
|
Prefetch('images', queryset=ArticleImage.objects.order_by('-main'))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GalleryView(ListAPIView):
|
class GalleryView(ListAPIView):
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
<template>
|
|
||||||
<h1>ncdsk</h1>Hoja
|
|
||||||
</template>
|
|
||||||
<script setup lang="ts">
|
|
||||||
</script>
|
|
Loading…
Reference in a new issue