diff --git a/taxi/urls.py b/taxi/urls.py index c663d6e22..a8981c334 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -4,9 +4,15 @@ index, CarListView, CarDetailView, + CarCreateView, + CarUpdateView, + CarDeleteView, DriverListView, DriverDetailView, ManufacturerListView, + ManufacturerCreateView, + ManufacturerUpdateView, + ManufacturerDeleteView, ) urlpatterns = [ @@ -16,8 +22,26 @@ ManufacturerListView.as_view(), name="manufacturer-list", ), + path( + "manufacturers/create/", + ManufacturerCreateView.as_view(), + name="manufacturer-create" + ), + path( + "manufacturers//update/", + ManufacturerUpdateView.as_view(), + name="manufacturer-update" + ), + path( + "manufacturers//delete/", + ManufacturerDeleteView.as_view(), + name="manufacturer-delete" + ), path("cars/", CarListView.as_view(), name="car-list"), path("cars//", CarDetailView.as_view(), name="car-detail"), + path("cars/create/", CarCreateView.as_view(), name="car-create"), + path("cars//update/", CarUpdateView.as_view(), name="car-update"), + path("cars//delete/", CarDeleteView.as_view(), name="car-delete"), path("drivers/", DriverListView.as_view(), name="driver-list"), path( "drivers//", DriverDetailView.as_view(), name="driver-detail" diff --git a/taxi/views.py b/taxi/views.py index 4a99a2cd9..e832b77dd 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,5 +1,6 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import render +from django.urls import reverse_lazy from django.views import generic from django.contrib.auth.mixins import LoginRequiredMixin @@ -34,6 +35,26 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView): paginate_by = 5 +class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView): + model = Manufacturer + fields = "__all__" + template_name = "taxi/manufacturer_form.html" + success_url = reverse_lazy("taxi:manufacturer-list") + + +class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView): + model = Manufacturer + fields = "__all__" + template_name = "taxi/manufacturer_form.html" + success_url = reverse_lazy("taxi:manufacturer-list") + + +class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Manufacturer + success_url = reverse_lazy("taxi:manufacturer-list") + template_name = "taxi/manufacturer_confirm_delete.html" + + class CarListView(LoginRequiredMixin, generic.ListView): model = Car paginate_by = 5 @@ -44,6 +65,26 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView): model = Car +class CarCreateView(LoginRequiredMixin, generic.CreateView): + model = Car + fields = "__all__" + template_name = "taxi/car_form.html" + success_url = reverse_lazy("taxi:car-list") + + +class CarUpdateView(LoginRequiredMixin, generic.UpdateView): + model = Car + fields = "__all__" + template_name = "taxi/car_form.html" + success_url = reverse_lazy("taxi:car-list") + + +class CarDeleteView(LoginRequiredMixin, generic.DeleteView): + model = Car + success_url = reverse_lazy("taxi:car-list") + template_name = "taxi/car_confirm_delete.html" + + class DriverListView(LoginRequiredMixin, generic.ListView): model = Driver paginate_by = 5 diff --git a/taxi_service/settings.py b/taxi_service/settings.py index d89c45643..8f98f33e6 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -43,6 +43,7 @@ "django.contrib.messages", "django.contrib.staticfiles", "debug_toolbar", + "crispy_forms", "taxi", ] @@ -75,6 +76,8 @@ }, ] +CRISPY_TEMPLATE_PACK = "bootstrap4" + WSGI_APPLICATION = "taxi_service.wsgi.application" diff --git a/templates/base.html b/templates/base.html index f4a0b6cfd..3e0343c9e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -6,9 +6,9 @@ + href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" + integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" + crossorigin="anonymous"> {% load static %} diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html index 78262d29d..f4d9d710c 100644 --- a/templates/includes/sidebar.html +++ b/templates/includes/sidebar.html @@ -1,9 +1,9 @@