diff --git a/adminpanel/__init__.py b/adminpanel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adminpanel/asgi.py b/adminpanel/asgi.py new file mode 100644 index 0000000..d50be14 --- /dev/null +++ b/adminpanel/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for adminpanel project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adminpanel.settings') + +application = get_asgi_application() diff --git a/adminpanel/settings.py b/adminpanel/settings.py new file mode 100644 index 0000000..5f0db0b --- /dev/null +++ b/adminpanel/settings.py @@ -0,0 +1,145 @@ +""" +Django settings for adminpanel project. + +Generated by 'django-admin startproject' using Django 3.2.7. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-&*wgpp^3&oy(ga4ag=)g-smhm3c=y9f3cgziob2x)(g#53q7i0' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'shopadmin.apps.ShopadminConfig', + 'django_filters', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'adminpanel.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'adminpanel.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.postgresql', +# 'NAME': 'TESTTASK', +# 'USER': 'postgres', +# 'PASSWORD': 'Sgs249791k*', +# 'HOST': 'localhost', +# 'PORT': '54324' +# } +# } + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'Europe/Kiev' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, 'static') +] + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') diff --git a/adminpanel/urls.py b/adminpanel/urls.py new file mode 100644 index 0000000..743a8ca --- /dev/null +++ b/adminpanel/urls.py @@ -0,0 +1,28 @@ +"""adminpanel URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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.contrib import admin +from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('shopadmin.urls')), +] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, + document_root=settings.MEDIA_ROOT) diff --git a/adminpanel/wsgi.py b/adminpanel/wsgi.py new file mode 100644 index 0000000..c30027a --- /dev/null +++ b/adminpanel/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for adminpanel project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adminpanel.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..b64513a --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adminpanel.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/media/images/2930685.png b/media/images/2930685.png new file mode 100644 index 0000000..5e4827b Binary files /dev/null and b/media/images/2930685.png differ diff --git a/media/images/500_F_227982973_bnWbiIhVPBwIKvnmUuLHORK5k7ncmMJE.jpg b/media/images/500_F_227982973_bnWbiIhVPBwIKvnmUuLHORK5k7ncmMJE.jpg new file mode 100644 index 0000000..c3e9c8b Binary files /dev/null and b/media/images/500_F_227982973_bnWbiIhVPBwIKvnmUuLHORK5k7ncmMJE.jpg differ diff --git a/media/images/500_F_227982973_bnWbiIhVPBwIKvnmUuLHORK5k7ncmMJE_1.jpg b/media/images/500_F_227982973_bnWbiIhVPBwIKvnmUuLHORK5k7ncmMJE_1.jpg new file mode 100644 index 0000000..c3e9c8b Binary files /dev/null and b/media/images/500_F_227982973_bnWbiIhVPBwIKvnmUuLHORK5k7ncmMJE_1.jpg differ diff --git a/media/images/743007.png b/media/images/743007.png new file mode 100644 index 0000000..871ba73 Binary files /dev/null and b/media/images/743007.png differ diff --git a/media/images/777205.png b/media/images/777205.png new file mode 100644 index 0000000..0511613 Binary files /dev/null and b/media/images/777205.png differ diff --git a/media/images/Wallpaper.png b/media/images/Wallpaper.png new file mode 100644 index 0000000..686ec02 Binary files /dev/null and b/media/images/Wallpaper.png differ diff --git a/media/images/shop.png b/media/images/shop.png new file mode 100644 index 0000000..7550b46 Binary files /dev/null and b/media/images/shop.png differ diff --git a/media/images/unnamed.png b/media/images/unnamed.png new file mode 100644 index 0000000..1312215 Binary files /dev/null and b/media/images/unnamed.png differ diff --git a/shopadmin/__init__.py b/shopadmin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shopadmin/admin.py b/shopadmin/admin.py new file mode 100644 index 0000000..77cfdf5 --- /dev/null +++ b/shopadmin/admin.py @@ -0,0 +1,44 @@ +from django.contrib import admin +from .models import Shop, Product, Order, ProductImage, Group + + +class ProductImageAdmin(admin.StackedInline): + model = ProductImage + + +@admin.register(Shop) +class ShopAdmin(admin.ModelAdmin): + list_display = 'shop_id', 'title', 'imagetoupload', 'date' + list_filter = 'title', 'date' + search_fields = ['title'] + + +@admin.register(Product) +class ProductAdmin(admin.ModelAdmin): + list_display = ( + 'product_id', + 'title', + 'amount', + 'price', + 'active', + ) + search_fields = ['product_id', 'title'] + inlines = [ProductImageAdmin] + + class Meta: + model = Product + + +@admin.register(Order) +class OrderAdmin(admin.ModelAdmin): + list_display = 'shop', 'product', 'date_created', 'status' + + +@admin.register(ProductImage) +class ProductImageAdmin(admin.ModelAdmin): + pass + + +@admin.register(Group) +class GroupAdmin(admin.ModelAdmin): + pass diff --git a/shopadmin/apps.py b/shopadmin/apps.py new file mode 100644 index 0000000..e1978cb --- /dev/null +++ b/shopadmin/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ShopadminConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'shopadmin' diff --git a/shopadmin/filters.py b/shopadmin/filters.py new file mode 100644 index 0000000..9e42d30 --- /dev/null +++ b/shopadmin/filters.py @@ -0,0 +1,19 @@ +import django_filters +from django_filters import BooleanFilter, RangeFilter +from .models import * + + +class ShopFilter(django_filters.FilterSet): + class Meta: + model = Shop + fields = ['title'] + + +class ProductFilter(django_filters.FilterSet): + active_sort = BooleanFilter(field_name='active') + price = RangeFilter() + + class Meta: + model = Product + fields = ['product_id', 'title'] + exclude = ['active', 'price'] diff --git a/shopadmin/forms.py b/shopadmin/forms.py new file mode 100644 index 0000000..3e18cb6 --- /dev/null +++ b/shopadmin/forms.py @@ -0,0 +1,22 @@ +from django.forms import ModelForm +from .models import Shop, Product + + +class ShopForm(ModelForm): + class Meta: + model = Shop + fields = ['title', 'description', 'imageUrl'] + + +class ProductForm(ModelForm): + class Meta: + model = Product + fields = [ + 'description', + 'title', + 'amount', + 'price', + 'active', + 'image', + 'category' + ] diff --git a/shopadmin/models.py b/shopadmin/models.py new file mode 100644 index 0000000..ca79392 --- /dev/null +++ b/shopadmin/models.py @@ -0,0 +1,65 @@ +from django.db import models + + +class Shop(models.Model): + shop_id = models.AutoField(primary_key=True) + title = models.CharField(max_length=50) + description = models.CharField(max_length=1000, null=True) + imageUrl = models.URLField(max_length=200, null=True) + date = models.DateField(auto_now_add=True, null=True) + imagetoupload = models.ImageField(upload_to='images', null=True) + + class Meta: + ordering = ['shop_id'] + + def __str__(self): + return self.title + + +class Product(models.Model): + product_id = models.AutoField(primary_key=True) + description = models.CharField(max_length=1000, null=True) + title = models.CharField(max_length=50) + amount = models.IntegerField() + price = models.FloatField(default=0, null=True) + active = models.BooleanField(default=False) + image = models.URLField(max_length=200, null=True, blank=True) + category = models.ManyToManyField('Group') + + class Meta: + ordering = ['product_id'] + + def __str__(self): + return self.title + + +class ProductImage(models.Model): + product = models.ForeignKey(Product, on_delete=models.CASCADE) + images = models.URLField(max_length=200, null=True) + + def __str__(self): + return self.product.title + + +class Group(models.Model): + name = models.CharField(max_length=200, null=True) + + def __str__(self): + return self.name + + +class Order(models.Model): + STATUS = ( + ('Pending', 'Pending'), + ('Out for delivery', 'Out for delivery'), + ('Delivered', 'Delivered') + ) + shop = models.ForeignKey(Shop, null=True, + on_delete=models.SET_NULL) + product = models.ForeignKey(Product, null=True, + on_delete=models.SET_NULL) + date_created = models.DateTimeField(auto_now_add=True, null=True) + status = models.CharField(max_length=200, null=True, choices=STATUS) + + def __str__(self): + return f'{self.product.title}' diff --git a/shopadmin/templates/shopadmin/main.html b/shopadmin/templates/shopadmin/main.html new file mode 100644 index 0000000..2d0d3f6 --- /dev/null +++ b/shopadmin/templates/shopadmin/main.html @@ -0,0 +1,24 @@ +{% load static %} + + + + + Main + + + + + + {% include 'shopadmin/navbar.html' %} + + {% block content %} + + {% endblock %} + + + + + + + + \ No newline at end of file diff --git a/shopadmin/templates/shopadmin/navbar.html b/shopadmin/templates/shopadmin/navbar.html new file mode 100644 index 0000000..87e4c19 --- /dev/null +++ b/shopadmin/templates/shopadmin/navbar.html @@ -0,0 +1,17 @@ +{% load static %} + \ No newline at end of file diff --git a/shopadmin/templates/shopadmin/orderform_product.html b/shopadmin/templates/shopadmin/orderform_product.html new file mode 100644 index 0000000..82783cc --- /dev/null +++ b/shopadmin/templates/shopadmin/orderform_product.html @@ -0,0 +1,19 @@ +{% extends 'shopadmin/main.html' %} +{% load static %} +{% block content %} + +
+
+
+
+ {% csrf_token %} + {{ form }} +

+ +
+ +
+
+
+ +{% endblock content %} \ No newline at end of file diff --git a/shopadmin/templates/shopadmin/orderform_shop.html b/shopadmin/templates/shopadmin/orderform_shop.html new file mode 100644 index 0000000..68ab7c3 --- /dev/null +++ b/shopadmin/templates/shopadmin/orderform_shop.html @@ -0,0 +1,19 @@ +{% extends 'shopadmin/main.html' %} +{% load static %} +{% block content %} + +
+
+
+
+ {% csrf_token %} + {{ form }} +

+ +
+ +
+
+
+ +{% endblock content %} \ No newline at end of file diff --git a/shopadmin/templates/shopadmin/product_detail.html b/shopadmin/templates/shopadmin/product_detail.html new file mode 100644 index 0000000..0dabe17 --- /dev/null +++ b/shopadmin/templates/shopadmin/product_detail.html @@ -0,0 +1,22 @@ +{% extends 'shopadmin/main.html' %} + +{% block content %} +
+

{{ product.title }}

+
+
+
+
+ {% for photo in photos %} + {% if forloop.counter == 1 %} +

{{ photo.images }}

+ {% endif %} + {% endfor %} +

id: {{ product.product_id }}

+

description: {{ product.description }}

+

price: {{ product.price }}

+

status: {{ product.active }}

+
+
+
+{% endblock content %} diff --git a/shopadmin/templates/shopadmin/products.html b/shopadmin/templates/shopadmin/products.html new file mode 100644 index 0000000..14d38de --- /dev/null +++ b/shopadmin/templates/shopadmin/products.html @@ -0,0 +1,48 @@ +{% extends 'shopadmin/main.html' %} + +{% block content %} +
+
+
+
+

Products: {{ total_products }}

+
+
+
+
+
+ {{ my_filter.form }} + +
+
+
+
+
+ + + + + + + + + {% for product in products %} + + + + + + {% if product.active %} + + {% else %} + + {% endif %} + + + {% endfor %} +
idImageTitlePriceStatus
{{ product.product_id }}{{ product.image }}{{ product.title }}{{ product.price }}ExistsSold outUpdate
+
+
+
+ +{% endblock %} diff --git a/shopadmin/templates/shopadmin/shop_detail.html b/shopadmin/templates/shopadmin/shop_detail.html new file mode 100644 index 0000000..9de8920 --- /dev/null +++ b/shopadmin/templates/shopadmin/shop_detail.html @@ -0,0 +1,30 @@ +{% extends 'shopadmin/main.html' %} + +{% block content %} +

Shop detail

+

{{ shop.title }}

+
+
+
+
+ + + + + + + + {% for order in orders %} + + + + + + + {% endfor %} +
Product idTitleStatusPrice
{{ order.product.product_id }}{{ order.product.title }}{{ order.status }}{{ order.product.price }}
+
+
+
+ +{% endblock content %} \ No newline at end of file diff --git a/shopadmin/templates/shopadmin/shops.html b/shopadmin/templates/shopadmin/shops.html new file mode 100644 index 0000000..6a830e3 --- /dev/null +++ b/shopadmin/templates/shopadmin/shops.html @@ -0,0 +1,45 @@ +{% extends 'shopadmin/main.html' %} + +{% block content %} + +
+
+
+
+

Shops: {{ total_shops }}

+
+
+
+
+
+ {{ my_filter.form }} + +
+
+
+
+
+
+
+ + + + + + + {% for shop in shops %} + + + + + + + {% endfor %} +
TitleDescriprion
View + {{ shop.title }} +
+ +
{{ shop.description }}Update
+
+ +{% endblock content%} diff --git a/shopadmin/tests.py b/shopadmin/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/shopadmin/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/shopadmin/urls.py b/shopadmin/urls.py new file mode 100644 index 0000000..6b9dec5 --- /dev/null +++ b/shopadmin/urls.py @@ -0,0 +1,13 @@ +from django.urls import path +from django.conf import settings +from django.conf.urls.static import static +from .views import * + +urlpatterns = [ + path('', home, name='home'), + path('products/', products, name='products'), + path('shop//', shop_detail, name='shop_detail'), + path('update_shop//', update_shop, name='update_shop'), + path('update_product//', update_product, name='update_product'), + path('products//', product_detail, name='product_detail'), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/shopadmin/views.py b/shopadmin/views.py new file mode 100644 index 0000000..593d626 --- /dev/null +++ b/shopadmin/views.py @@ -0,0 +1,79 @@ +from django.shortcuts import render, redirect, get_object_or_404 +from .models import * +from .forms import ShopForm, ProductForm +from .filters import ShopFilter, ProductFilter, RangeFilter +from django.db.models import Count + + +def home(request): + shops = Shop.objects.all() + total_shops = shops.count() + my_filter = ShopFilter(request.GET, queryset=shops) + shops = my_filter.qs + context = { + 'shops': shops, + 'total_shops': total_shops, + 'my_filter': my_filter, + } + return render(request, 'shopadmin/shops.html', context) + + +def products(request): + products = Product.objects.all().order_by('price') + total_products = products.count() + my_filter = ProductFilter(request.GET, queryset=products) + products = my_filter.qs + context = { + 'products': products, + 'total_products': total_products, + 'my_filter': my_filter, + } + return render(request, 'shopadmin/products.html', context) + + +def product_detail(request, pk): + product = get_object_or_404(Product, product_id=pk) + photos = ProductImage.objects.filter(product=product) + context = { + 'product': product, + 'photos': photos + } + return render(request, 'shopadmin/product_detail.html', context) + + +def shop_detail(request, pk): + shop = Shop.objects.get(shop_id=pk) + orders = shop.order_set.all() + context = { + 'shop': shop, + 'orders': orders, + } + return render(request, 'shopadmin/shop_detail.html', context) + + +def update_shop(request, pk): + shop = Shop.objects.get(shop_id=pk) + form = ShopForm(instance=shop) + if request.method == 'POST': + form = ShopForm(request.POST, instance=shop) + if form.is_valid(): + form.save() + return redirect('/') + context = { + 'form': form + } + return render(request, 'shopadmin/orderform_shop.html', context) + + +def update_product(request, pk): + product = Product.objects.get(product_id=pk) + form = ProductForm(instance=product) + if request.method == 'POST': + form = ProductForm(request.POST, instance=product) + if form.is_valid(): + form.save() + return redirect('/') + context = { + 'form': form + } + return render(request, 'shopadmin/orderform_product.html', context) diff --git a/static/css/main.css b/static/css/main.css new file mode 100644 index 0000000..2e70689 --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,23 @@ +#logo { +} + +body { + background-color: #ebeff5; +} + +#total-orders { + background-color: #4cb4c7; +} + +#orders-delivered { + background-color: #7abecc; +} + +#orders-pending { + background-color: #7CD1C0; +} + +.shop_photo { + width: 60px; + height: 60px; +} \ No newline at end of file diff --git a/static/images/shop (1).png b/static/images/shop (1).png new file mode 100644 index 0000000..df2c76b Binary files /dev/null and b/static/images/shop (1).png differ diff --git a/static/images/shop.png b/static/images/shop.png new file mode 100644 index 0000000..d7419c3 Binary files /dev/null and b/static/images/shop.png differ