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

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
10 changes: 10 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body {
margin-top: 20px;
}
a {
text-decoration: none;
}
.sidebar-nav {
padding: 0;
list-style: none;
}
17 changes: 17 additions & 0 deletions taxi/migrations/0002_alter_manufacturer_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1 on 2024-11-12 14:25

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('taxi', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='manufacturer',
options={'ordering': ['name']},
),
]
12 changes: 12 additions & 0 deletions taxi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ class Manufacturer(models.Model):
name = models.CharField(max_length=255, unique=True)
country = models.CharField(max_length=255)

class Meta:
ordering = ['name']

def __str__(self):
return self.name


class Driver(AbstractUser):
license_number = models.CharField(max_length=255, unique=True)

def __str__(self):
return self.username


class Car(models.Model):
model = models.CharField(max_length=255)
manufacturer = models.ForeignKey(
Manufacturer, on_delete=models.CASCADE, related_name="cars"
)
drivers = models.ManyToManyField(Driver, related_name="cars")

def __str__(self):
return self.model
11 changes: 11 additions & 0 deletions taxi/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin
from django.urls import path

from taxi import views

urlpatterns = [
path("admin/", admin.site.urls),
path("", views.index, name="index"),
]

app_name = "taxi"
15 changes: 15 additions & 0 deletions taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render

from taxi.models import Driver, Manufacturer, Car


# Create your views here.

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,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
3 changes: 3 additions & 0 deletions taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"""
from django.contrib import admin
from django.urls import path
from django.urls.conf import include

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

34 changes: 34 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!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 %}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" 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-2">
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}
</div>

<div class="col-sm-10">
{% block content %}

{% endblock %}
</div>
</div>
</div>

</body>
</html>
6 changes: 6 additions & 0 deletions templates/includes/sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ul class="sidebar-nav">
<li><a class="links" href="{% url 'taxi:index' %}">Home page</a></li>
<li><a class="links" href="#">Manufacturers</a></li>
<li><a class="links" href="#">Cars</a></li>
<li><a class="links" href="#">Drivers</a></li>
Comment on lines +3 to +5

Choose a reason for hiding this comment

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

The links for 'Manufacturers', 'Cars', and 'Drivers' are placeholders. Consider updating them with actual URLs using the {% url %} template tag once the corresponding views and URL patterns are defined.

Serhii-Chubur marked this conversation as resolved.
Show resolved Hide resolved
</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 %}
<h1>Welcome to the taxi service</h1>
<h3>Taxi service content</h3>
<ul>
<li>Number of cars {{ num_cars }}</li>
<li>Number of drivers {{ num_drivers }}</li>
<li>Number of manufacturers {{ num_manufacturers }}</li>
</ul>
{% endblock content %}
Loading