Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Solution' #858

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion taxi/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
from django.urls import path

from .views import index
from .views import (
index,
ManufacturerListView,
CarListView,
CarDetailView,
DriverDetailView,
DriverListView
)

urlpatterns = [
path("", index, name="index"),
path(
"manufacturers/",
ManufacturerListView.as_view(),
name="manufacturer-list"
),
path(
"cars/",
CarListView.as_view(),
name="car-list"
),
path(
"cars/<int:pk>/",
CarDetailView.as_view(),
name="car-detail")
,
path(
"drivers/",
DriverListView.as_view(),
name="driver-list"
),
path(
"drivers/<int:pk>/",
DriverDetailView.as_view(),
name="driver-detail"
),

]

app_name = "taxi"
26 changes: 26 additions & 0 deletions taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.shortcuts import render
from django.views import generic

from taxi.models import Driver, Car, Manufacturer

Expand All @@ -13,3 +14,28 @@ def index(request):
}

return render(request, "taxi/index.html", context=context)


class ManufacturerListView(generic.ListView):
model = Manufacturer
queryset = Manufacturer.objects.order_by("name")
paginate_by = 5


class CarListView(generic.ListView):
model = Car
queryset = Car.objects.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
2 changes: 1 addition & 1 deletion taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
31 changes: 31 additions & 0 deletions templates/includes/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% if is_paginated %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item">
{% if is_paginated %}
<a href="?page={{ page_obj.previous_page_number }}" class="page-link">Prev</a>
{% else %}
<a href="#" class="page-link">1</a>
{% endif %}
</li>
{% else %}
<li class="page-item disabled">
<a href="#" class="page-link">Prev</a>
</li>
{% endif %}

<li class="page-item active">
<span class="page-link">{{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span>
</li>

{% if page_obj.has_next %}
<li class="page-item">
<a href="?page={{ page_obj.next_page_number }}" class="page-link">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<a href="#" class="page-link">Next</a>
</li>
{% endif %}
</ul>
{% endif %}
8 changes: 4 additions & 4 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ul class="sidebar-nav">
<li><a href="#">Home page</a></li>
<li><a href="#">Manufacturers</a></li>
<li><a href="#">Cars</a></li>
<li><a href="#">Drivers</a></li>
<li><a href={% url 'taxi:index' %}>Home page</a></li>
<li><a href={% url 'taxi:manufacturer-list' %}>Manufacturers</a></li>
<li><a href={% url 'taxi:car-list' %}>Cars</a></li>
<li><a href={% url 'taxi:driver-list' %}>Drivers</a></li>
</ul>
10 changes: 10 additions & 0 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}

{% block content %}
<h2>Car of detail</h2>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
<p>{{ car.manufacturer.name }}</p>
<p>{{ car.manufacturer.country }}</p>
<p>{% for driver in car.drivers.all %}
{{ driver.first_name }} {{ driver.last_name}}
{% endfor %}</p>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
{% endblock %}
12 changes: 12 additions & 0 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block content %}
<h2>Car of list</h2>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
{% if car_list %}
<ul>
{% for car in car_list %}
<li><a href={% url 'taxi:car-detail' car.id %}>{{ car.model }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
11 changes: 11 additions & 0 deletions templates/taxi/driver_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block content %}
<h2>Driver of detail</h2>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
<p>{{ driver.first_name }} {{ driver.last_name}}</p>
<ul>
{% for driver in driver.cars.all %}
<li>{{ driver.model}}</li>
{% endfor %}
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
</ul>
{% endblock %}
12 changes: 12 additions & 0 deletions templates/taxi/driver_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block content %}
<h2>Driver of list</h2>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
{% if driver_list %}
<ul>
{% for driver in driver_list %}
<li><a href={% url 'taxi:driver-detail' driver.id %}>{{ driver.first_name }} {{ driver.last_name}}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
12 changes: 12 additions & 0 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}

{% block content %}
<h2>Manufacturers of list</h2>
AlexTarasov57 marked this conversation as resolved.
Show resolved Hide resolved
{% if manufacturer_list %}
<ul>
{% for manufacturer in manufacturer_list %}
<li>{{ manufacturer.name }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
Loading