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 #868

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions taxi/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.urls import reverse
popeye88 marked this conversation as resolved.
Show resolved Hide resolved


class Manufacturer(models.Model):
Expand Down
14 changes: 13 additions & 1 deletion taxi/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from django.urls import path

from .views import index
from .views import CarDetailView, CarListView, DriverDetailView, \
popeye88 marked this conversation as resolved.
Show resolved Hide resolved
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/<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"
28 changes: 28 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.generic import DetailView, ListView

from taxi.models import Driver, Car, Manufacturer

Expand All @@ -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()
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)
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{% block content %}{% endblock %}

{% block pagination %}
{% include "includes/pagination.html" %}
{% endblock %}

</div>
Expand Down
27 changes: 27 additions & 0 deletions templates/includes/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% if is_paginated %}
<ul class="pagination d-flex justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item d-inline-flex">
<a class="page-link" href="?page=1">&laquo; first</a>
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">
Prev
</a>
</li>
{% endif %}

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

{% if page_obj.has_next %}
<li class="page-item d-inline-flex">
<a class="page-link" href="?page={{ page_obj.next_page_number }}">
Next
</a>
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</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>
35 changes: 35 additions & 0 deletions templates/taxi/car_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% extends "base.html" %}

{% block content %}
<div class="ml-3">

<h3>
<strong>{{ car.model }}</strong> details:
</h3>

<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Model</th>
<th scope="col">Manufacturer</th>
<th scope="col">Drivers</th>
</tr>
</thead>

<tbody>
<tr>
<th scope="row">{{ car.id }}</th>
<td>{{ car.model }}</td>
<td>{{ car.manufacturer.name }}</td>
<td>
{% for driver in car.drivers.all %}
<a href="{% url 'taxi:driver-detail' driver.id %}">{{ driver.username }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
</td>
</tr>
</tbody>
</table>
</div>
{% endblock %}
popeye88 marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 32 additions & 0 deletions templates/taxi/car_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends "base.html" %}

{% block content %}
<div class="ml-3">

<h3>
Cars:
</h3>

<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Model</th>
<th scope="col">Manufacturer</th>
</tr>
</thead>

<tbody>
{% for car in car_list %}
<tr>
<th scope="row">
<a href="{% url 'taxi:car-detail' car.id %}">{{ car.id }}</a>
</th>
<td>{{ car.model }}</td>
<td>{{ car.manufacturer.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
39 changes: 39 additions & 0 deletions templates/taxi/driver_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "base.html" %}

{% block content %}
<div class="ml-3">

<h3>
Driver <strong>{{ driver.username }}</strong> details:
</h3>

<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Username</th>
<th scope="col">First name</th>
<th scope="col">Last name</th>
<th scope="col">License number</th>
<th scope="col">Cars</th>
</tr>
</thead>

<tbody>
<tr>
<th scope="row">{{ driver.id }}</th>
<td>{{ driver.username }}</td>
<td>{{ driver.first_name }}</td>
<td>{{ driver.last_name }}</td>
<td>{{ driver.license_number }}</td>
<td>
{% for car in driver.cars.all %}
<a href="{% url 'taxi:car-detail' car.id %}">{{ car.model }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
</td>
</tr>
</tbody>
</table>
</div>
{% endblock %}
popeye88 marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 32 additions & 0 deletions templates/taxi/driver_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends "base.html" %}

{% block content %}
<div class="ml-3">

<h3>
Drivers:
</h3>

<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Username</th>
<th scope="col">License number</th>
</tr>
</thead>

<tbody>
{% for driver in driver_list %}
<tr>
<th scope="row">{{ driver.id }}</th>
<td>
<a href="{% url 'taxi:driver-detail' driver.id %}">{{ driver.username }}</a>
</td>
<td>{{ driver.license_number }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
30 changes: 30 additions & 0 deletions templates/taxi/manufacturer_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "base.html" %}

{% block content %}
<div class="ml-3">

<h3>
Manufacturers:
</h3>

<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Manufacturer</th>
<th scope="col">Country</th>
</tr>
</thead>

<tbody>
{% for manufacturer in manufacturer_list %}
<tr>
<th scope="row">{{ manufacturer.id }}</th>
<td>{{ manufacturer.name }}</td>
<td>{{ manufacturer.country }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
Loading