first commit

This commit is contained in:
2026-02-22 12:29:18 +05:00
commit d34447d322
40 changed files with 585 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
venv
+89
View File
@@ -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)
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.
Binary file not shown.
+13
View File
@@ -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")
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class AutoappConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "autoapp"
+37
View File
@@ -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
+77
View File
@@ -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"],
},
),
]
View File
+50
View File
@@ -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})"
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+7
View File
@@ -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'),
]
+21
View File
@@ -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})
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

+22
View File
@@ -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()
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+16
View File
@@ -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()
+123
View File
@@ -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"
+24
View File
@@ -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')),
]
+16
View File
@@ -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()
+55
View File
@@ -0,0 +1,55 @@
{% block content %}
<div class="container mt-5">
<h2>Добавить автомобиль</h2>
{% if messages %}
<div class="mt-3">
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
</div>
{% endif %}
<form method="post" class="mt-4">
{% csrf_token %}
<div class="mb-3">
<label for="{{ form.brand.id_for_label }}" class="form-label">Марка</label>
{{ form.brand }}
{% if form.brand.errors %}
<div class="text-danger">{{ form.brand.errors }}</div>
{% endif %}
</div>
<div class="mb-3">
<label for="{{ form.model.id_for_label }}" class="form-label">Модель</label>
{{ form.model }}
{% if form.model.errors %}
<div class="text-danger">{{ form.model.errors }}</div>
{% endif %}
</div>
<div class="mb-3">
<label for="{{ form.year.id_for_label }}" class="form-label">Год выпуска</label>
{{ form.year }}
{% if form.year.errors %}
<div class="text-danger">{{ form.year.errors }}</div>
{% endif %}
</div>
<div class="mb-3">
<label for="{{ form.color.id_for_label }}" class="form-label">Цвет</label>
{{ form.color }}
{% if form.color.errors %}
<div class="text-danger">{{ form.color.errors }}</div>
{% endif %}
</div>
<button type="submit" class="btn btn-primary">Сохранить автомобиль</button>
<a href="{% url 'auto_list' %}" class="btn btn-secondary">Отмена</a>
</form>
</div>
{% endblock %}
+25
View File
@@ -0,0 +1,25 @@
<h2>Список автомобилей</h2>
<a href="{% url 'add_auto' %}" class="btn btn-success mb-3">Добавить автомобиль</a>
<table class="table table-striped">
<thead>
<tr>
<th>Марка</th>
<th>Модель</th>
<th>Год</th>
<th>Цвет</th>
</tr>
</thead>
<tbody>
{% for auto in autos %}
<tr>
<td>{{ auto.brand }}</td>
<td>{{ auto.model }}</td>
<td>{{ auto.year }}</td>
<td>{{ auto.color|default:"—" }}</td>
</tr>
{% empty %}
<tr><td colspan="4">Автомобили пока не добавлены</td></tr>
{% endfor %}
</tbody>
</table>