Add another

This commit is contained in:
ack
2026-01-21 01:46:12 +03:00
parent 7088d1e498
commit daf734cafb
32 changed files with 300 additions and 0 deletions

0
products/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

6
products/admin.py Normal file
View File

@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Product
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'price', 'weight')

6
products/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ProductsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'products'

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.10 on 2026-01-20 21:54
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, verbose_name='Название')),
('price', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Цена')),
('weight', models.FloatField(verbose_name='Вес (кг)')),
],
),
]

View File

9
products/models.py Normal file
View File

@@ -0,0 +1,9 @@
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=255, verbose_name="Название")
price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="Цена")
weight = models.FloatField(verbose_name="Вес (кг)")
def __str__(self):
return self.name

View File

@@ -0,0 +1,8 @@
<h1>Список товаров</h1>
<ul>
{% for p in products %}
<li>{{ p.name }} — Цена: {{ p.price }} руб. ({{ p.weight }} кг)</li>
{% empty %}
<li>Товаров пока нет.</li>
{% endfor %}
</ul>

3
products/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
products/urls.py Normal file
View File

@@ -0,0 +1,6 @@
from django.urls import path
from .views import product_list
urlpatterns = [
path('', product_list, name='product_list'),
]

6
products/views.py Normal file
View File

@@ -0,0 +1,6 @@
from django.shortcuts import render
from .models import Product
def product_list(request):
items = Product.objects.all()
return render(request, 'products/list.html', {'products': items})