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

21
autoapp/views.py Normal file
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})