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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
96 changes: 96 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
*,
*::before,
*::after {
box-sizing: border-box;
}

a {
text-decoration: none;
color: #212121;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
color: inherit;
margin: 0;
padding: 0;
}

ul {
margin: 0;
padding: 0;
}

li {
list-style: none;
}

body {
font-family: "Roboto", "Lucida Grande", Verdana, Arial, sans-serif;
font-size: 14px;

background-color: #fff;
color: #212121
}


.container {
width: 1200px;
margin: 0 auto;
padding: 0 15px;
outline: 1px solid red
}

.aside-link {
cursor: pointer;
padding: 5px;
font-size: 16px;
color: darkgray;
}

.aside-link:hover,
.aside-link:focus {
color: blueviolet;
}

header, footer {
background-color: #212121;
color: #fff;
padding: 20px;
text-align: center;
}

.wrapper {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-columns: 25% auto;
}

.aside-item {
margin-top: 15px;
}

main {
padding: 20px;
}

.data-list {
font-size: 16px;
color: darkgray;
}

.data-item:not(:first-child){
margin-top: 15px;
}

footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
4 changes: 4 additions & 0 deletions taxi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Manufacturer(models.Model):
class Driver(AbstractUser):
license_number = models.CharField(max_length=255, unique=True)

class Meta:
verbose_name = "driver"
verbose_name_plural = "drivers"


class Car(models.Model):
model = models.CharField(max_length=255)
Expand Down
6 changes: 6 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path

from taxi.views import index

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add blank line

urlpatterns = [
path("", index, name="index"),
]
21 changes: 20 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render

# Create your views here.
from taxi.models import Manufacturer, Car, Driver


def index(request: HttpRequest) -> HttpResponse:
num_drivers = Driver.objects.count()
num_manufacturers = Manufacturer.objects.count()
num_cars = Car.objects.count()

context = {
"num_drivers": num_drivers,
"num_manufacturers": num_manufacturers,
"num_cars": num_cars
}

return render(
request,
"taxi/index.html",
context=context
)
8 changes: 6 additions & 2 deletions taxi_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [
BASE_DIR / "templates"
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -123,7 +125,9 @@
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = "static/"

STATICFILES_DIRS = [
BASE_DIR / "static"
]
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

Expand Down
4 changes: 3 additions & 1 deletion taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include


urlpatterns = [
path("admin/", admin.site.urls),
path("", include(("taxi.urls", "taxi"), namespace="taxi"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to much parenthesis (

]
28 changes: 28 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
{% block title %}
<title>Taxi Service</title>
{% endblock %}
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<header>
<h1>Welcome to TAXI</h1>
</header>
<div class="wrapper">
<aside>
{% block aside %} {% include "includes/sidebar.html" %} {% endblock %}
</aside>
<main>{% block content %} {% endblock %}</main>
</div>
<footer>
<h2>Footer</h2>
</footer>
</body>
</html>
14 changes: 14 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul class="aside">
<li class="aside-item">
<a href="{% url "taxi:index" %}" class="aside-link">Home page</a>
</li>
<li class="aside-item">
<a href="#" class="aside-link">Manufactures</a>
</li>
<li class="aside-item">
<a href="#" class="aside-link">Cars</a>
</li>
<li class="aside-item">
<a href="#" class="aside-link">Drivers</a>
</li>
</ul>
9 changes: 9 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}

{% block content %}
<ul class="data-list">
<li class="data-item">Count of cars: {{ num_cars }}</li>
<li class="data-item">Count of manufactures: {{ num_manufacturers }}</li>
<li class="data-item">Count of drivers: {{ num_drivers }}</li>
</ul>
{% endblock %}
Loading