diff --git a/static/css/styles.css b/static/css/styles.css index 1d8a1b3de..390172edb 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1,3 +1,4 @@ body { margin-top: 20px; + background: beige; } diff --git a/taxi/urls.py b/taxi/urls.py index d1911da6b..4e4bd861d 100644 --- a/taxi/urls.py +++ b/taxi/urls.py @@ -1,9 +1,23 @@ from django.urls import path -from .views import index +from .views import ( + index, + ManufacturerListView, + CarListView, + CarDetailView, + DriverListView, + DriverDetailView +) + 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..c0344c4d3 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -1,4 +1,5 @@ from django.shortcuts import render +from django.views import generic from taxi.models import Driver, Car, Manufacturer @@ -13,3 +14,29 @@ def index(request): } return render(request, "taxi/index.html", context=context) + + +class ManufacturerListView(generic.ListView): + model = Manufacturer + queryset = Manufacturer.objects.all().order_by("name") + paginate_by = 5 + + +class CarListView(generic.ListView): + model = Car + queryset = Car.objects.all().select_related("manufacturer") + paginate_by = 5 + + +class CarDetailView(generic.DetailView): + model = Car + + +class DriverListView(generic.ListView): + model = Driver + paginate_by = 5 + + +class DriverDetailView(generic.DetailView): + model = Driver + queryset = Driver.objects.all().prefetch_related("cars__drivers") diff --git a/templates/base.html b/templates/base.html index 272284d17..598f8c10f 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 %} @@ -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..8499ab33d --- /dev/null +++ b/templates/includes/pagination.html @@ -0,0 +1,14 @@ +{% block pagination %} + {% if is_paginated %} + + {% endif %} +{% endblock %} diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html index b42a684ac..f5632bc91 100644 --- a/templates/includes/sidebar.html +++ b/templates/includes/sidebar.html @@ -1,6 +1,14 @@ diff --git a/templates/taxi/car_detail.html b/templates/taxi/car_detail.html new file mode 100644 index 000000000..243be57c4 --- /dev/null +++ b/templates/taxi/car_detail.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block content %} +

+ Car: {{ car.model }} +

+

Manufacturer: + {{ car.manufacturer.name }} ({{ car.manufacturer.country }}) +

+
+

Drivers:

+ {% for driver in car.drivers.all %} +
+

Username: {{ driver }}

+

First name: {{ driver.first_name }}

+

Last name: {{ driver.last_name }}

+

License number: {{ driver.license_number }}

+ {% 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..7be005f0a --- /dev/null +++ b/templates/taxi/car_list.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block content %} +

Car list

+ {% if car_list %} + + {% endif %} +{% endblock %} diff --git a/templates/taxi/driver_detail.html b/templates/taxi/driver_detail.html new file mode 100644 index 000000000..7d1e579b0 --- /dev/null +++ b/templates/taxi/driver_detail.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block content %} +

+ Driver: {{ driver.first_name }} {{ driver.last_name }} +

+

Username: {{ driver.username }}

+

E-mail: {{ driver.email }}

+

License number: {{ driver.license_number }}

+
+

Cars:

+ {% for car in driver.cars.all %} +
+

ID: {{ car.id }}

+

Car: {{ car.model }}

+ {% 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..27a653a7b --- /dev/null +++ b/templates/taxi/driver_list.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block content %} +

Driver list

+ {% if driver_list %} + + {% endif %} +{% endblock %} diff --git a/templates/taxi/manufacturer_list.html b/templates/taxi/manufacturer_list.html new file mode 100644 index 000000000..a8fbe5f11 --- /dev/null +++ b/templates/taxi/manufacturer_list.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block content %} +

Manufacturer list

+ {% if manufacturer_list %} + + {% endif %} +{% endblock %}