From 584162a0834a3a05765c1288598fec24c7251f2a Mon Sep 17 00:00:00 2001 From: S-SMTN Date: Fri, 28 Jul 2023 01:28:31 +0300 Subject: [PATCH] implemented urls and templates --- static/css/styles.css | 0 taxi/models.py | 3 ++- taxi/urls.py | 9 +++++++++ taxi/views.py | 18 +++++++++++++++++- taxi_service/settings.py | 8 ++++++-- taxi_service/urls.py | 7 +++++-- templates/base.html | 18 ++++++++++++++++++ templates/includes/sidebar.html | 6 ++++++ templates/taxi/index.html | 9 +++++++++ 9 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 static/css/styles.css create mode 100644 taxi/urls.py create mode 100644 templates/base.html create mode 100644 templates/includes/sidebar.html create mode 100644 templates/taxi/index.html diff --git a/static/css/styles.css b/static/css/styles.css new file mode 100644 index 000000000..e69de29bb diff --git a/taxi/models.py b/taxi/models.py index 2861a656f..d92965900 100644 --- a/taxi/models.py +++ b/taxi/models.py @@ -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): @@ -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") diff --git a/taxi/urls.py b/taxi/urls.py new file mode 100644 index 000000000..cd370a862 --- /dev/null +++ b/taxi/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from taxi.views import index + +urlpatterns = [ + path("", index, name="index") +] + +app_name = "taxi" diff --git a/taxi/views.py b/taxi/views.py index 91ea44a21..4cfc2531f 100644 --- a/taxi/views.py +++ b/taxi/views.py @@ -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) diff --git a/taxi_service/settings.py b/taxi_service/settings.py index 00329f55f..8c8d45314 100644 --- a/taxi_service/settings.py +++ b/taxi_service/settings.py @@ -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'. @@ -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": [ @@ -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 diff --git a/taxi_service/urls.py b/taxi_service/urls.py index 57c939e7f..a743cacf6 100644 --- a/taxi_service/urls.py +++ b/taxi_service/urls.py @@ -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) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 000000000..49b7548ad --- /dev/null +++ b/templates/base.html @@ -0,0 +1,18 @@ + + + + + {% block title %} + Taxi Service + {% endblock %} + {% load static %} + + + + {% block sidebar %} + {% include "includes/sidebar.html" %} + {% endblock %} + {% block content %} + {% endblock %} + + diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html new file mode 100644 index 000000000..b0fe9d3a2 --- /dev/null +++ b/templates/includes/sidebar.html @@ -0,0 +1,6 @@ + diff --git a/templates/taxi/index.html b/templates/taxi/index.html new file mode 100644 index 000000000..5365ec771 --- /dev/null +++ b/templates/taxi/index.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + +{% block content %} +
  • + + + +
  • +{% endblock %}