summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspl3g <spleefer6@gmail.com>2026-05-29 21:05:25 +0300
committerspl3g <spleefer6@gmail.com>2026-05-29 21:18:21 +0300
commit4d408ecd6df06bc73eba586a404813c3bb818e99 (patch)
tree8d1cc5d9887484ed6ee23f38998361a7f6cade3f
parent9a7ca8a6cbab866d6ce6b1eb12e5977f7f2a9367 (diff)
update some settings and add models
-rw-r--r--config/asgi.py2
-rw-r--r--config/settings.py17
-rw-r--r--config/wsgi.py2
-rw-r--r--core/models.py69
-rwxr-xr-xmanage.py2
5 files changed, 83 insertions, 9 deletions
diff --git a/config/asgi.py b/config/asgi.py
index 7f391de..2358b5d 100644
--- a/config/asgi.py
+++ b/config/asgi.py
@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shoes.settings')
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
application = get_asgi_application()
diff --git a/config/settings.py b/config/settings.py
index 5e15f6b..ed0ea02 100644
--- a/config/settings.py
+++ b/config/settings.py
@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
+ 'core'
]
MIDDLEWARE = [
@@ -49,7 +50,7 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
-ROOT_URLCONF = 'shoes.urls'
+ROOT_URLCONF = 'config.urls'
TEMPLATES = [
{
@@ -66,16 +67,20 @@ TEMPLATES = [
},
]
-WSGI_APPLICATION = 'shoes.wsgi.application'
+WSGI_APPLICATION = 'config.wsgi.application'
# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': BASE_DIR / 'db.sqlite3',
+ "default": {
+ "ENGINE": "django.db.backends.postgresql",
+ "NAME": "shoe_store",
+ "USER": "postgres",
+ "PASSWORD": "123456",
+ "HOST": "localhost",
+ "PORT": "5445",
}
}
@@ -98,6 +103,8 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
+AUTH_USER_MODEL = 'core.User'
+
# Internationalization
# https://docs.djangoproject.com/en/6.0/topics/i18n/
diff --git a/config/wsgi.py b/config/wsgi.py
index 10ecb99..7407718 100644
--- a/config/wsgi.py
+++ b/config/wsgi.py
@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shoes.settings')
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
application = get_wsgi_application()
diff --git a/core/models.py b/core/models.py
index 71a8362..dce67cf 100644
--- a/core/models.py
+++ b/core/models.py
@@ -1,3 +1,70 @@
+from django.contrib.auth.models import AbstractUser
from django.db import models
-# Create your models here.
+class Role(models.Model):
+ name = models.CharField(max_length=50, unique=True, verbose_name="Name of the role")
+
+ def __str__(self) -> str:
+ return self.name
+
+class User(AbstractUser):
+ role = models.ForeignKey(Role, on_delete=models.SET_NULL, null=True, blank=True)
+ full_name = models.CharField(max_length=255)
+
+
+class Supplier(models.Model):
+ name = models.CharField(max_length=200, unique=True)
+
+ def __str__(self) -> str:
+ return self.name
+
+
+class PickupPoint(models.Model):
+ address = models.TextField()
+
+ def __str__(self) -> str:
+ return self.address[:50]
+
+class Product(models.Model):
+ article = models.CharField(max_length=50, unique=True)
+ name = models.CharField(max_length=200)
+ unit = models.CharField(max_length=20)
+ price = models.DecimalField(max_digits=20, decimal_places=2)
+ manufacturer = models.CharField(max_length=200)
+ supplier = models.CharField(max_length=200)
+ category = models.CharField(max_length=100)
+ discount = models.DecimalField(max_digits=5, decimal_places=2, default=0)
+ quantity = models.IntegerField(default=0)
+ description = models.TextField()
+ photo = models.ImageField(upload_to="products/", null=True, blank=True)
+
+ def save(self, *args, **kwargs):
+ try:
+ this = Product.objects.get(id=self.id)
+ if this.photo and self.photo and this.photo != self.photo:
+ this.photo.delete(save=False)
+ except Exception:
+ pass
+ super().save(*args, **kwargs)
+
+ @property
+ def final_price(self):
+ return self.price * (1 - self.discount / 100) if self.discount else self.price
+
+
+ def __str__(self) -> str:
+ return self.name
+
+class Order(models.Model):
+ order_date = models.DateTimeField(auto_now_add=True)
+ delivery_date = models.DateTimeField()
+ pickup_point = models.ForeignKey(PickupPoint, on_delete=models.CASCADE)
+ client_name = models.CharField(max_length=255, null=True, blank=True)
+ pickup_code = models.IntegerField()
+ status = models.CharField(max_length=50, default="Новый")
+ user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
+
+class OrderItem(models.Model):
+ order = models.ForeignKey(Order, related_name="items", on_delete=models.CASCADE)
+ product = models.ForeignKey(Product, on_delete=models.CASCADE)
+ count = models.IntegerField()
diff --git a/manage.py b/manage.py
index 2cbb872..8e7ac79 100755
--- a/manage.py
+++ b/manage.py
@@ -6,7 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shoes.settings')
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc: