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 %} + + +
+ +{{ photo.images }}
+ {% endif %} + {% endfor %} +id: {{ product.product_id }}
+description: {{ product.description }}
+price: {{ product.price }}
+status: {{ product.active }}
+| id | +Image | +Title | +Price | +Status | +||
|---|---|---|---|---|---|---|
| {{ product.product_id }} | +{{ product.image }} | +{{ product.title }} | +{{ product.price }} | + {% if product.active %} +Exists | + {% else %} +Sold out | + {% endif %} +Update | +
| Product id | +Title | +Status | +Price | +
|---|---|---|---|
| {{ order.product.product_id }} | +{{ order.product.title }} | +{{ order.status }} | +{{ order.product.price }} | +
| + | Title | +Descriprion | +|
|---|---|---|---|
| View | +
+ {{ shop.title }}
+ + |
+ {{ shop.description }} | +Update | +