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

@@ -3,4 +3,6 @@ from .models import Product
@admin.register(Product)
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
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="Цена")
weight = models.FloatField(verbose_name="Вес (кг)")
image = models.ImageField(upload_to='products/', null=True, blank=True, verbose_name="Изображение")
def __str__(self):
return self.name

View File

@@ -1,8 +1,33 @@
<h1>Список товаров</h1>
<ul>
{% for p in products %}
<li>{{ p.name }} — Цена: {{ p.price }} руб. ({{ p.weight }} кг)</li>
{% empty %}
<li>Товаров пока нет.</li>
{% endfor %}
</ul>
<!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>
<a href="/admin/" class="admin-link">Перейти в панель админа</a>
<hr>
{% 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 %}
<p>Товаров пока нет.</p>
{% endfor %}
</body>
</html>