From 611f3017c00dd9a220402489602defab66f2c9f0 Mon Sep 17 00:00:00 2001 From: spl3g Date: Sun, 31 May 2026 16:12:10 +0300 Subject: add login and products views --- config/settings.py | 7 ++++-- config/urls.py | 11 ++++++++++ core/templates/core/base.html | 41 +++++++++++++++++++++++++++++++++++ core/templates/core/login.html | 31 ++++++++++++++++++++++++++ core/templates/core/product_list.html | 41 +++++++++++++++++++++++++++++++++++ core/views.py | 12 +++++++++- 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 core/templates/core/base.html create mode 100644 core/templates/core/login.html create mode 100644 core/templates/core/product_list.html diff --git a/config/settings.py b/config/settings.py index ed0ea02..8ba7d50 100644 --- a/config/settings.py +++ b/config/settings.py @@ -80,7 +80,7 @@ DATABASES = { "USER": "postgres", "PASSWORD": "123456", "HOST": "localhost", - "PORT": "5445", + "PORT": "4444", } } @@ -120,5 +120,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/6.0/howto/static-files/ +STATIC_URL = "static/" +STATICFILES_DIRS = [BASE_DIR / "static"] +MEDIA_URL = "/media/" +MEDIA_ROOT = BASE_DIR / "media" -STATIC_URL = 'static/' diff --git a/config/urls.py b/config/urls.py index 56f8c8c..ff27744 100644 --- a/config/urls.py +++ b/config/urls.py @@ -16,7 +16,18 @@ Including another URLconf """ from django.contrib import admin from django.urls import path +from django.contrib.auth.views import LogoutView +from django.conf import settings +from django.conf.urls.static import static + +from core.views import UserLoginView, ProductListView urlpatterns = [ path('admin/', admin.site.urls), + path("", UserLoginView.as_view(), name="login"), + path("logout/", LogoutView.as_view(), name="logout"), + path("products/", ProductListView.as_view(), name="products"), ] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/core/templates/core/base.html b/core/templates/core/base.html new file mode 100644 index 0000000..56d9e17 --- /dev/null +++ b/core/templates/core/base.html @@ -0,0 +1,41 @@ +{% load static %} + + + + + {% block title %}ООО «Обувь»{% endblock %} + + + + +
+
+ оОобувь +
+
+ {% if user.is_authenticated %} + {{ user.role.name }} + {{ user.full_name }} +
+ {% csrf_token %} + +
+ {% else %} + Гость | + Войти + {% endif %} +
+
+ +
+

{% block h1 %}{% endblock %}

+ + {% if messages %} + {% for message in messages %} +
{{message}}
+ {% endfor %} + {% endif %} + + {% block content %}{% endblock %} +
+ diff --git a/core/templates/core/login.html b/core/templates/core/login.html new file mode 100644 index 0000000..c17f521 --- /dev/null +++ b/core/templates/core/login.html @@ -0,0 +1,31 @@ +{% extends 'core/base.html' %} + +{% block title %}Авторизация - ООобувь{% endblock %} +{% block h1 %}Вход в систему{% endblock %} + +{% block content %} +
+
+ {% csrf_token %} + {% if form.errors %} +
+ {% for field in form %} + {% for error in field.errors %} + {{ error }} + {% endfor %} + {% endfor %} + + {% for error in form.non_field_errors %} + {{ error }} + {% endfor %} +
+ {% endif %} + + + + + + +
+
+{% endblock %} diff --git a/core/templates/core/product_list.html b/core/templates/core/product_list.html new file mode 100644 index 0000000..ac4b8c7 --- /dev/null +++ b/core/templates/core/product_list.html @@ -0,0 +1,41 @@ +{% extends 'core/base.html' %} +{% load static %} + +{% block title %}Список товаров - ООбувь{% endblock %} +{% block h1 %}Каталог товаров{% endblock %} + +{% block content %} +
+ {% for product in products %} +
+ {% if product.photo %} + {{ product.name }} + {% else %} + Заглушка + {% endif %} +
+ {{product.category}} | {{product.name}} +
+ Описание товара: {{ product.description }} +
+ Производитель: {{ product.manufacturer }} +
+ Поставщик: {{ product.supplier.name }} +
+ {% if product.discount > 0 %} + Цена: {{ product.price }} {{ product.final_price|floatformat:2 }} руб. + {% else %} + Цена: {{ product.price }} руб. + {% endif %} +
+ Единица измерения: {{ product.unit }} +
+ Колличество на складе: {{ product.discount }} +
+
{{ product.discount }}
+
+ {% endfor %} +
+{% endblock %} diff --git a/core/views.py b/core/views.py index 91ea44a..6957abc 100644 --- a/core/views.py +++ b/core/views.py @@ -1,3 +1,13 @@ from django.shortcuts import render +from django.views.generic import ListView +from django.contrib.auth.views import LoginView -# Create your views here. +from .models import Product + +class UserLoginView(LoginView): + template_name = "core/login.html" + +class ProductListView(ListView): + model = Product + template_name = "core/product_list.html" + context_object_name = "products" -- cgit v1.2.3