Fix os import and add media settings 6

This commit is contained in:
ack
2026-01-21 05:02:13 +03:00
parent 155c0d8436
commit 31423d168d
10 changed files with 87 additions and 19 deletions

View File

@@ -80,12 +80,6 @@ DATABASES = {
} }
} }
# добавил от жемени из за нжинкса
CSRF_TRUSTED_ORIGINS = [
"http://192.168.1.57:8080",
"https://shop.tertelius.space", # Сразу добавь на будущее
]
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
@@ -109,9 +103,11 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/ # https://docs.djangoproject.com/en/5.2/topics/i18n/
LANGUAGE_CODE = 'en-us' # LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'UTC' # TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True USE_I18N = True
@@ -132,3 +128,10 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# добавил от жемени из за нжинкса
CSRF_TRUSTED_ORIGINS = [
"http://192.168.1.57:8080",
"https://shop.tertelius.space", # Сразу добавь на будущее
]

View File

@@ -4,6 +4,10 @@
echo "Collecting static files..." echo "Collecting static files..."
python manage.py collectstatic --noinput python manage.py collectstatic --noinput
# Применяем миграции базы данных
echo "Applying database migrations..."
python manage.py migrate --noinput
# Запускаем основную команду (Gunicorn) # Запускаем основную команду (Gunicorn)
echo "Starting Gunicorn..." echo "Starting Gunicorn..."
exec "$@" exec "$@"

View File

@@ -3,4 +3,6 @@ from .models import Product
@admin.register(Product) @admin.register(Product)
class ProductAdmin(admin.ModelAdmin): class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'price', 'weight') # Убираем 'weight', добавляем 'image'
list_display = ('name', 'price', 'image')
search_fields = ('name',)

View File

@@ -0,0 +1,33 @@
# Generated by Django 5.2.10 on 2026-01-21 02:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('products', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='product',
name='weight',
),
migrations.AddField(
model_name='product',
name='description',
field=models.TextField(default=1, verbose_name='Описание'),
preserve_default=False,
),
migrations.AddField(
model_name='product',
name='image',
field=models.ImageField(blank=True, null=True, upload_to='products/', verbose_name='Изображение'),
),
migrations.AlterField(
model_name='product',
name='name',
field=models.CharField(max_length=200, verbose_name='Название'),
),
]

View File

@@ -1,9 +1,10 @@
from django.db import models from django.db import models
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=255, verbose_name="Название") name = models.CharField(max_length=200, verbose_name="Название")
description = models.TextField(verbose_name="Описание")
price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Цена") price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Цена")
weight = models.FloatField(verbose_name="Вес (кг)") image = models.ImageField(upload_to='products/', null=True, blank=True, verbose_name="Изображение")
def __str__(self): def __str__(self):
return self.name return self.name

View File

@@ -1,8 +1,33 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Мой Магазин</title>
<style>
body { font-family: sans-serif; margin: 40px; }
.product { border-bottom: 1px solid #ccc; padding: 10px; margin-bottom: 10px; }
.admin-link { background: #417690; color: white; padding: 10px; text-decoration: none; border-radius: 4px; }
img { max-width: 200px; height: auto; display: block; margin-top: 10px; }
</style>
</head>
<body>
<h1>Список товаров</h1> <h1>Список товаров</h1>
<ul> <a href="/admin/" class="admin-link">Перейти в панель админа</a>
{% for p in products %} <hr>
<li>{{ p.name }} — Цена: {{ p.price }} руб. ({{ p.weight }} кг)</li>
{% for product in products %}
<div class="product">
<h2>{{ product.name }}</h2>
<p>{{ product.description }}</p>
<p><strong>Цена: {{ product.price }} руб.</strong></p>
{% if product.image %}
<img src="{{ product.image.url }}" alt="{{ product.name }}">
{% else %}
<p>Нет изображения</p>
{% endif %}
</div>
{% empty %} {% empty %}
<li>Товаров пока нет.</li> <p>Товаров пока нет.</p>
{% endfor %} {% endfor %}
</ul> </body>
</html>

Binary file not shown.