21 lines
735 B
Python
21 lines
735 B
Python
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}) |