Add another
This commit is contained in:
0
products/__init__.py
Normal file
0
products/__init__.py
Normal file
BIN
products/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
products/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
products/__pycache__/admin.cpython-311.pyc
Normal file
BIN
products/__pycache__/admin.cpython-311.pyc
Normal file
Binary file not shown.
BIN
products/__pycache__/apps.cpython-311.pyc
Normal file
BIN
products/__pycache__/apps.cpython-311.pyc
Normal file
Binary file not shown.
BIN
products/__pycache__/models.cpython-311.pyc
Normal file
BIN
products/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
products/__pycache__/urls.cpython-311.pyc
Normal file
BIN
products/__pycache__/urls.cpython-311.pyc
Normal file
Binary file not shown.
BIN
products/__pycache__/views.cpython-311.pyc
Normal file
BIN
products/__pycache__/views.cpython-311.pyc
Normal file
Binary file not shown.
6
products/admin.py
Normal file
6
products/admin.py
Normal 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
6
products/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ProductsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'products'
|
||||
23
products/migrations/0001_initial.py
Normal file
23
products/migrations/0001_initial.py
Normal 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='Вес (кг)')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
products/migrations/__init__.py
Normal file
0
products/migrations/__init__.py
Normal file
BIN
products/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
products/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
BIN
products/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
products/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
9
products/models.py
Normal file
9
products/models.py
Normal 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
|
||||
8
products/templates/products/list.html
Normal file
8
products/templates/products/list.html
Normal 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
3
products/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
6
products/urls.py
Normal file
6
products/urls.py
Normal 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
6
products/views.py
Normal 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})
|
||||
Reference in New Issue
Block a user