commit d34447d322f9f7066f9b5a09dc65e52e45b3b5ba Author: Boris Tsirenshchikov Date: Sun Feb 22 12:29:18 2026 +0500 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5e96db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7bb4db4 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +# Autospp + +Короткое описание проекта: что это за приложение, для чего предназначено (1–3 предложения). + +Пример: +Простое приложение для учета автомобилей (марки, модели, год выпуска, фото). Использует Django 5.2.11 и SQLite/PostgreSQL. + +## Требования + +- Windows 10 / 11 +- Python 3.12+ (рекомендуется 3.13 или 3.14) + +## Установка на Windows + +### 1. Установка Python + +1. Скачай и установи Python с официального сайта: + https://www.python.org/downloads/ + +2. **Важно** во время установки: + - Поставь галочку **«Add python.exe to PATH»** + - Выбери «Customize installation» → включи pip и py launcher + +3. Проверь установку (в PowerShell или cmd): + +```powershell +python --version +# должно показать Python 3.13.x или выше +pip --version +``` + +### 2. Создание и активация виртуального окруженияРекомендуется всегда использовать виртуальное окружение.Открой терминал (PowerShell или cmd) в папке с проектом и выполни: + +```powershell +python -m venv venv + +# Активация (нужно делать каждый раз при работе с проектом) +venv\Scripts\activate +``` +После активации в начале строки появится (venv) + +### 3. Установка зависимостей + +```powershell +# Обнови pip (рекомендуется) +python -m pip install --upgrade pip +# или +.\venv\Scripts\python.exe -m pip install --upgrade pip + +# Установи Django и все зависимости +pip install pip install Django==5.2.11 +``` + +### 4. Настройка и первый запуск + +```powershell +# Применить миграции (создать/обновить таблицы в базе) +python manage.py migrate + +# (Опционально) Создать суперпользователя для админки +python manage.py createsuperuser +# → введи username, email и пароль + +# Запустить сервер разработки +python manage.py runserver +``` + +После запуска открой в браузере: + +http://127.0.0.1:8000/admin/autoapp/auto/ + +http://127.0.0.1:8000/autoapp/ + +http://127.0.0.1:8000/autoapp/add/ + +## Добавление через админку +![alt text](image-5.png) + +![alt text](image-1.png) + +![alt text](image-2.png) + +## Добавление через сайт + +![alt text](image.png) + +![alt text](image-3.png) + +![alt text](image-4.png) \ No newline at end of file diff --git a/autoapp/__init__.py b/autoapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/autoapp/__pycache__/__init__.cpython-311.pyc b/autoapp/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..38ab6ac Binary files /dev/null and b/autoapp/__pycache__/__init__.cpython-311.pyc differ diff --git a/autoapp/__pycache__/admin.cpython-311.pyc b/autoapp/__pycache__/admin.cpython-311.pyc new file mode 100644 index 0000000..7169251 Binary files /dev/null and b/autoapp/__pycache__/admin.cpython-311.pyc differ diff --git a/autoapp/__pycache__/apps.cpython-311.pyc b/autoapp/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..d19b495 Binary files /dev/null and b/autoapp/__pycache__/apps.cpython-311.pyc differ diff --git a/autoapp/__pycache__/forms.cpython-311.pyc b/autoapp/__pycache__/forms.cpython-311.pyc new file mode 100644 index 0000000..0902029 Binary files /dev/null and b/autoapp/__pycache__/forms.cpython-311.pyc differ diff --git a/autoapp/__pycache__/models.cpython-311.pyc b/autoapp/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..790c53e Binary files /dev/null and b/autoapp/__pycache__/models.cpython-311.pyc differ diff --git a/autoapp/__pycache__/urls.cpython-311.pyc b/autoapp/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..d1b2b0c Binary files /dev/null and b/autoapp/__pycache__/urls.cpython-311.pyc differ diff --git a/autoapp/__pycache__/views.cpython-311.pyc b/autoapp/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..69547d2 Binary files /dev/null and b/autoapp/__pycache__/views.cpython-311.pyc differ diff --git a/autoapp/admin.py b/autoapp/admin.py new file mode 100644 index 0000000..ff33311 --- /dev/null +++ b/autoapp/admin.py @@ -0,0 +1,13 @@ +from django.contrib import admin + +# Register your models here. + +from .models import Auto + + +@admin.register(Auto) +class AutoAdmin(admin.ModelAdmin): + list_display = ("brand", "model", "year", "color", "created_at") + list_filter = ("brand", "year", "color") + search_fields = ("brand", "model") + ordering = ("-year", "brand") \ No newline at end of file diff --git a/autoapp/apps.py b/autoapp/apps.py new file mode 100644 index 0000000..2019714 --- /dev/null +++ b/autoapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AutoappConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "autoapp" diff --git a/autoapp/forms.py b/autoapp/forms.py new file mode 100644 index 0000000..2262906 --- /dev/null +++ b/autoapp/forms.py @@ -0,0 +1,37 @@ +from django import forms +from .models import Auto + + +class AutoForm(forms.ModelForm): + class Meta: + model = Auto + fields = ['brand', 'model', 'year', 'color'] + + # Настройка виджетов и стилей (опционально, но улучшает внешний вид) + widgets = { + 'brand': forms.TextInput(attrs={ + 'class': 'form-control', + 'placeholder': 'Например: Toyota, BMW, Lada' + }), + 'model': forms.TextInput(attrs={ + 'class': 'form-control', + 'placeholder': 'Например: Camry, X5, Granta' + }), + 'year': forms.NumberInput(attrs={ + 'class': 'form-control', + 'placeholder': 'Год выпуска (например, 2023)', + 'min': 1900, + 'max': 2100, + }), + 'color': forms.TextInput(attrs={ + 'class': 'form-control', + 'placeholder': 'Например: чёрный, серебристый, красный' + }), + } + + # Дополнительная валидация (опционально) + def clean_year(self): + year = self.cleaned_data.get('year') + if year and (year < 1900 or year > 2100): + raise forms.ValidationError("Год выпуска должен быть в разумных пределах (1900–2100)") + return year \ No newline at end of file diff --git a/autoapp/migrations/0001_initial.py b/autoapp/migrations/0001_initial.py new file mode 100644 index 0000000..5cee842 --- /dev/null +++ b/autoapp/migrations/0001_initial.py @@ -0,0 +1,77 @@ +# Generated by Django 5.2.11 on 2026-02-22 06:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Auto", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "brand", + models.CharField( + help_text="Например: Toyota, BMW, Lada", + max_length=100, + verbose_name="Марка", + ), + ), + ( + "model", + models.CharField( + help_text="Например: Camry, X5, Granta", + max_length=100, + verbose_name="Модель", + ), + ), + ( + "year", + models.PositiveIntegerField( + help_text="Год выпуска автомобиля (например, 2023)", + verbose_name="Год выпуска", + ), + ), + ( + "color", + models.CharField( + blank=True, + default="Не указан", + help_text="Например: чёрный, серебристый, красный", + max_length=50, + verbose_name="Цвет", + ), + ), + ( + "created_at", + models.DateTimeField( + auto_now_add=True, verbose_name="Дата создания записи" + ), + ), + ( + "updated_at", + models.DateTimeField( + auto_now=True, verbose_name="Дата последнего изменения" + ), + ), + ], + options={ + "verbose_name": "Автомобиль", + "verbose_name_plural": "Автомобили", + "ordering": ["-year", "brand", "model"], + }, + ), + ] diff --git a/autoapp/migrations/__init__.py b/autoapp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/autoapp/migrations/__pycache__/0001_initial.cpython-311.pyc b/autoapp/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..6ca55ea Binary files /dev/null and b/autoapp/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/autoapp/migrations/__pycache__/__init__.cpython-311.pyc b/autoapp/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..13153ea Binary files /dev/null and b/autoapp/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/autoapp/models.py b/autoapp/models.py new file mode 100644 index 0000000..43a27cc --- /dev/null +++ b/autoapp/models.py @@ -0,0 +1,50 @@ +from django.db import models + +# Create your models here. + +class Auto(models.Model): + """Модель автомобиля""" + + brand = models.CharField( + max_length=100, + verbose_name="Марка", + help_text="Например: Toyota, BMW, Lada" + ) + + model = models.CharField( + max_length=100, + verbose_name="Модель", + help_text="Например: Camry, X5, Granta" + ) + + year = models.PositiveIntegerField( + verbose_name="Год выпуска", + help_text="Год выпуска автомобиля (например, 2023)", + ) + + color = models.CharField( + max_length=50, + verbose_name="Цвет", + blank=True, # можно не указывать цвет + null=False, + default="Не указан", + help_text="Например: чёрный, серебристый, красный" + ) + + created_at = models.DateTimeField( + auto_now_add=True, + verbose_name="Дата создания записи" + ) + + updated_at = models.DateTimeField( + auto_now=True, + verbose_name="Дата последнего изменения" + ) + + class Meta: + verbose_name = "Автомобиль" + verbose_name_plural = "Автомобили" + ordering = ["-year", "brand", "model"] + + def __str__(self): + return f"{self.brand} {self.model} ({self.year})" \ No newline at end of file diff --git a/autoapp/tests.py b/autoapp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/autoapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/autoapp/urls.py b/autoapp/urls.py new file mode 100644 index 0000000..4330241 --- /dev/null +++ b/autoapp/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('add/', views.AutoCreateView.as_view(), name='add_auto'), + path('', views.auto_list, name='auto_list'), +] \ No newline at end of file diff --git a/autoapp/views.py b/autoapp/views.py new file mode 100644 index 0000000..91754b2 --- /dev/null +++ b/autoapp/views.py @@ -0,0 +1,21 @@ +from django.shortcuts import render +from django.views.generic import CreateView +from django.urls import reverse_lazy +from .models import Auto +from .forms import AutoForm +from django.contrib import messages + +class AutoCreateView(CreateView): + model = Auto + form_class = AutoForm + template_name = 'autoapp/add_auto.html' + success_url = reverse_lazy('auto_list') # или другая страница + + def form_valid(self, form): + response = super().form_valid(form) + messages.success(self.request, 'Автомобиль успешно добавлен!') + return response + +def auto_list(request): + autos = Auto.objects.all().order_by('-year', 'brand', 'model') + return render(request, 'autoapp/auto_list.html', {'autos': autos}) \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..4cf40a1 Binary files /dev/null and b/db.sqlite3 differ diff --git a/image-1.png b/image-1.png new file mode 100644 index 0000000..707bdfa Binary files /dev/null and b/image-1.png differ diff --git a/image-2.png b/image-2.png new file mode 100644 index 0000000..59bb1d4 Binary files /dev/null and b/image-2.png differ diff --git a/image-3.png b/image-3.png new file mode 100644 index 0000000..c4c3b56 Binary files /dev/null and b/image-3.png differ diff --git a/image-4.png b/image-4.png new file mode 100644 index 0000000..f22dd25 Binary files /dev/null and b/image-4.png differ diff --git a/image-5.png b/image-5.png new file mode 100644 index 0000000..851fbca Binary files /dev/null and b/image-5.png differ diff --git a/image.png b/image.png new file mode 100644 index 0000000..2416989 Binary files /dev/null and b/image.png differ diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..893db8e --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/myproject/__init__.py b/myproject/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/__pycache__/__init__.cpython-311.pyc b/myproject/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..64247f2 Binary files /dev/null and b/myproject/__pycache__/__init__.cpython-311.pyc differ diff --git a/myproject/__pycache__/settings.cpython-311.pyc b/myproject/__pycache__/settings.cpython-311.pyc new file mode 100644 index 0000000..27196d2 Binary files /dev/null and b/myproject/__pycache__/settings.cpython-311.pyc differ diff --git a/myproject/__pycache__/urls.cpython-311.pyc b/myproject/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..976cfc9 Binary files /dev/null and b/myproject/__pycache__/urls.cpython-311.pyc differ diff --git a/myproject/__pycache__/wsgi.cpython-311.pyc b/myproject/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 0000000..0330e1c Binary files /dev/null and b/myproject/__pycache__/wsgi.cpython-311.pyc differ diff --git a/myproject/asgi.py b/myproject/asgi.py new file mode 100644 index 0000000..4c6328e --- /dev/null +++ b/myproject/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for myproject project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") + +application = get_asgi_application() diff --git a/myproject/settings.py b/myproject/settings.py new file mode 100644 index 0000000..d56fd57 --- /dev/null +++ b/myproject/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for myproject project. + +Generated by 'django-admin startproject' using Django 5.2.11. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-q3@j)tjusy0#$qk^a%zx!f1k$rgxs$gand%-^v2gt35=f3lvp7" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "autoapp", + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "myproject.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + 'DIRS': [BASE_DIR / 'templates'], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "myproject.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/myproject/urls.py b/myproject/urls.py new file mode 100644 index 0000000..2f7505b --- /dev/null +++ b/myproject/urls.py @@ -0,0 +1,24 @@ +""" +URL configuration for myproject project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" + +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path("admin/", admin.site.urls), + path('autoapp/', include('autoapp.urls')), +] diff --git a/myproject/wsgi.py b/myproject/wsgi.py new file mode 100644 index 0000000..32f754c --- /dev/null +++ b/myproject/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for myproject project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") + +application = get_wsgi_application() diff --git a/templates/autoapp/add_auto.html b/templates/autoapp/add_auto.html new file mode 100644 index 0000000..ae9e2d1 --- /dev/null +++ b/templates/autoapp/add_auto.html @@ -0,0 +1,55 @@ +{% block content %} +
+

Добавить автомобиль

+ + {% if messages %} +
+ {% for message in messages %} + + {% endfor %} +
+ {% endif %} + +
+ {% csrf_token %} + +
+ + {{ form.brand }} + {% if form.brand.errors %} +
{{ form.brand.errors }}
+ {% endif %} +
+ +
+ + {{ form.model }} + {% if form.model.errors %} +
{{ form.model.errors }}
+ {% endif %} +
+ +
+ + {{ form.year }} + {% if form.year.errors %} +
{{ form.year.errors }}
+ {% endif %} +
+ +
+ + {{ form.color }} + {% if form.color.errors %} +
{{ form.color.errors }}
+ {% endif %} +
+ + + Отмена +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/autoapp/auto_list.html b/templates/autoapp/auto_list.html new file mode 100644 index 0000000..e1e9339 --- /dev/null +++ b/templates/autoapp/auto_list.html @@ -0,0 +1,25 @@ +

Список автомобилей

+Добавить автомобиль + + + + + + + + + + + + {% for auto in autos %} + + + + + + + {% empty %} + + {% endfor %} + +
МаркаМодельГодЦвет
{{ auto.brand }}{{ auto.model }}{{ auto.year }}{{ auto.color|default:"—" }}
Автомобили пока не добавлены
\ No newline at end of file