diff --git a/taxi/urls.py b/taxi/urls.py index d1911da6b..80613e1be 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -1,9 +1,21 @@ from django.urls import path -from .views import index +from taxi.views import CarDetailView, CarListView, DriverDetailView, \ + DriverListView, \ + ManufacturerListView, index urlpatterns = [ path("", index, name="index"), + path( + "manufacturers/", + ManufacturerListView.as_view(), + name="manufacturer-list" + ), + path("cars/", CarListView.as_view(), name="car-list"), + path("cars//", CarDetailView.as_view(), name="car-detail"), + path("drivers/", DriverListView.as_view(), name="driver-list"), + path("drivers//", DriverDetailView.as_view(), + name="driver-detail"), ] app_name = "taxi" diff --git a/taxi/views.py b/taxi/views.py index f69b5485b..e0a409aa4 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render +from django.views.generic import DetailView, ListView from taxi.models import Driver, Car, Manufacturer @@ -13,3 +14,30 @@ def index(request): } return render(request, "taxi/index.html", context=context) + + +class ManufacturerListView(ListView): + model = Manufacturer + queryset = Manufacturer.objects.order_by("name") + paginate_by = 5 + + +class CarListView(ListView): + model = Car + queryset = Car.objects.select_related("manufacturer").order_by("model") + paginate_by = 5 + + +class CarDetailView(DetailView): + model = Car + queryset = Car.objects.select_related("manufacturer").all() + + +class DriverListView(ListView): + model = Driver + paginate_by = 5 + + +class DriverDetailView(DetailView): + model = Driver + queryset = Driver.objects.prefetch_related("cars__manufacturer").all() diff --git a/taxi_service/urls.py b/taxi_service/urls.py index 8b94449f9..a0dd344d2 100644 --- a/taxi_service/urls.py +++ b/taxi_service/urls.py @@ -21,5 +21,5 @@ urlpatterns = [ path("admin/", admin.site.urls), - path("", include("taxi.urls", namespace="taxi")), + path("taxi/", include("taxi.urls", namespace="taxi")), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/templates/base.html b/templates/base.html index 272284d17..f4a0b6cfd 100644 --- a/templates/base.html +++ b/templates/base.html @@ -29,6 +29,7 @@ {% block content %}{% endblock %} {% block pagination %} + {% include "includes/pagination.html" %} {% endblock %} diff --git a/templates/includes/pagination.html b/templates/includes/pagination.html new file mode 100644 index 000000000..65add68b0 --- /dev/null +++ b/templates/includes/pagination.html @@ -0,0 +1,27 @@ +{% if is_paginated %} + +{% endif %} diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html index b42a684ac..e32a29f11 100644 --- a/templates/includes/sidebar.html +++ b/templates/includes/sidebar.html @@ -1,6 +1,6 @@ diff --git a/templates/taxi/car_detail.html b/templates/taxi/car_detail.html new file mode 100644 index 000000000..40eefb3ee --- /dev/null +++ b/templates/taxi/car_detail.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

+ {{ car.model }} details: +

+ + + + + + + + + + + + + + + + + + + +
IDModelManufacturerDrivers
{{ car.id }}{{ car.model }}{{ car.manufacturer.name }} + {% for driver in car.drivers.all %} + {{ driver.username }} + {% if not forloop.last %}, {% endif %} + {% empty %} + No drivers + {% endfor %} +
+
+{% endblock %} diff --git a/templates/taxi/car_list.html b/templates/taxi/car_list.html new file mode 100644 index 000000000..559de1e6b --- /dev/null +++ b/templates/taxi/car_list.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

+ Cars: +

+ + + + + + + + + + + + {% for car in car_list %} + + + + + + {% endfor %} + +
#ModelManufacturer
+ {{ car.id }} + {{ car.model }}{{ car.manufacturer.name }}
+
+{% endblock %} diff --git a/templates/taxi/driver_detail.html b/templates/taxi/driver_detail.html new file mode 100644 index 000000000..22d3a6036 --- /dev/null +++ b/templates/taxi/driver_detail.html @@ -0,0 +1,41 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

+ Driver {{ driver.username }} details: +

+ + + + + + + + + + + + + + + + + + + + + + + +
IDUsernameFirst nameLast nameLicense numberCars
{{ driver.id }}{{ driver.username }}{{ driver.first_name }}{{ driver.last_name }}{{ driver.license_number }} + {% for car in driver.cars.all %} + {{ car.model }} + {% if not forloop.last %}, {% endif %} + {% empty %} + No cars + {% endfor %} +
+
+{% endblock %} diff --git a/templates/taxi/driver_list.html b/templates/taxi/driver_list.html new file mode 100644 index 000000000..1960150b2 --- /dev/null +++ b/templates/taxi/driver_list.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

+ Drivers: +

+ + + + + + + + + + + + {% for driver in driver_list %} + + + + + + {% endfor %} + +
#UsernameLicense number
{{ driver.id }} + {{ driver.username }} + {{ driver.license_number }}
+
+{% endblock %} diff --git a/templates/taxi/manufacturer_list.html b/templates/taxi/manufacturer_list.html new file mode 100644 index 000000000..0dc5ad8f8 --- /dev/null +++ b/templates/taxi/manufacturer_list.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} + +{% block content %} +
+ +

+ Manufacturers: +

+ + + + + + + + + + + + {% for manufacturer in manufacturer_list %} + + + + + + {% endfor %} + +
#ManufacturerCountry
{{ manufacturer.id }}{{ manufacturer.name }}{{ manufacturer.country }}
+
+{% endblock %}