Skip to content

Commit

Permalink
'Solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey-Dementyev committed Nov 17, 2024
1 parent 9d92e66 commit c8e7a76
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 4 deletions.
8 changes: 8 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
margin-top: 20px;
}

.sidebar-nav {
padding: 0;
list-style: none;
}
9 changes: 9 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from taxi.views import index

urlpatterns = [
path("", index, name="index"),
]

app_name = "taxi"
14 changes: 13 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from .models import Car, Driver, Manufacturer

# Create your views here.

def index(request: HttpRequest) -> HttpResponse:
num_cars = Car.objects.count()
num_drivers = Driver.objects.count()
num_manufacturers = Manufacturer.objects.count()
context = {
"num_cars": num_cars,
"num_drivers": num_drivers,
"num_manufacturers": num_manufacturers,
}
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,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -112,7 +112,7 @@

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"
TIME_ZONE = "Europe/Kiev"

USE_I18N = True

Expand All @@ -124,6 +124,10 @@

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 @@ -13,9 +13,11 @@
1. Import the include() function: from django.urls import include, path
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", namespace="taxi"))
]
27 changes: 27 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Taxi Service</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}
</div>
<div class="col-sm-9">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</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="sidebar-nav">
<li>
<a href="{% url 'taxi:index' %}">Home page</a>
</li>
<li>
<a href="#">Manufacturers</a>
</li>
<li>
<a href="#">Cars</a>
</li>
<li>
<a href="#">Drivers</a>
</li>
</ul>
10 changes: 10 additions & 0 deletions templates/taxi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}

{% block content %}
<h2>Taxi service content:</h2>
<ul>
<li>Number of cars: {{ num_cars }}</li>
<li>Number of drivers: {{ num_drivers }}</li>
<li>Number of manufacturers: {{ num_manufacturers }}</li>
</ul>
{% endblock %}

0 comments on commit c8e7a76

Please sign in to comment.