Skip to content

Commit

Permalink
implemented urls and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
S-SMTN committed Jul 27, 2023
1 parent 358a6a4 commit 584162a
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 6 deletions.
Empty file added static/css/styles.css
Empty file.
3 changes: 2 additions & 1 deletion 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 taxi_service.settings import AUTH_USER_MODEL


class Manufacturer(models.Model):
Expand All @@ -18,4 +19,4 @@ class Meta:
class Car(models.Model):
model = models.CharField(max_length=255)
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)
drivers = models.ManyToManyField(Driver, related_name="cars")
drivers = models.ManyToManyField(AUTH_USER_MODEL, related_name="cars")
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"
18 changes: 17 additions & 1 deletion taxi/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
from django.shortcuts import render

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


def index(request: WSGIRequest) -> 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 @@ -9,7 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -56,7 +56,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -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
7 changes: 5 additions & 2 deletions taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
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"))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
18 changes: 18 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
{% block title %}
<title>Taxi Service</title>
{% endblock %}
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
{% block sidebar %}
{% include "includes/sidebar.html" %}
{% endblock %}
{% block content %}
{% endblock %}
</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>
<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>
</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 %}
<li>
<ul>Number of cars: {{num_cars}}</ul>
<ul>Number of drivers: {{num_drivers}}</ul>
<ul>Number of manufacturers: {{num_manufacturers}}</ul>
</li>
{% endblock %}

0 comments on commit 584162a

Please sign in to comment.