diff options
Diffstat (limited to 'django/learndjango')
30 files changed, 289 insertions, 0 deletions
diff --git a/django/learndjango/learndjango/db.sqlite3 b/django/learndjango/learndjango/db.sqlite3 Binary files differnew file mode 100644 index 0000000..a8a26dd --- /dev/null +++ b/django/learndjango/learndjango/db.sqlite3 diff --git a/django/learndjango/learndjango/learndjango/__init__.py b/django/learndjango/learndjango/learndjango/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/django/learndjango/learndjango/learndjango/__init__.py diff --git a/django/learndjango/learndjango/learndjango/__pycache__/__init__.cpython-313.pyc b/django/learndjango/learndjango/learndjango/__pycache__/__init__.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..1e6be5a --- /dev/null +++ b/django/learndjango/learndjango/learndjango/__pycache__/__init__.cpython-313.pyc diff --git a/django/learndjango/learndjango/learndjango/__pycache__/settings.cpython-313.pyc b/django/learndjango/learndjango/learndjango/__pycache__/settings.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..867b666 --- /dev/null +++ b/django/learndjango/learndjango/learndjango/__pycache__/settings.cpython-313.pyc diff --git a/django/learndjango/learndjango/learndjango/__pycache__/urls.cpython-313.pyc b/django/learndjango/learndjango/learndjango/__pycache__/urls.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..8e2884e --- /dev/null +++ b/django/learndjango/learndjango/learndjango/__pycache__/urls.cpython-313.pyc diff --git a/django/learndjango/learndjango/learndjango/__pycache__/wsgi.cpython-313.pyc b/django/learndjango/learndjango/learndjango/__pycache__/wsgi.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..78ed5a1 --- /dev/null +++ b/django/learndjango/learndjango/learndjango/__pycache__/wsgi.cpython-313.pyc diff --git a/django/learndjango/learndjango/learndjango/asgi.py b/django/learndjango/learndjango/learndjango/asgi.py new file mode 100644 index 0000000..3bb2b72 --- /dev/null +++ b/django/learndjango/learndjango/learndjango/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for learndjango project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'learndjango.settings') + +application = get_asgi_application() diff --git a/django/learndjango/learndjango/learndjango/settings.py b/django/learndjango/learndjango/learndjango/settings.py new file mode 100644 index 0000000..d1d2277 --- /dev/null +++ b/django/learndjango/learndjango/learndjango/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for learndjango project. + +Generated by 'django-admin startproject' using Django 5.2.7. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-!(tjx9d*5bqms=)!cw1ci8p(t85q4wktd%p5=tqb$uetu*5d@c" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "myapp.apps.MyappConfig", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "learndjango.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "learndjango.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = "static/" +STATICFILES_DIR = ( + os.path.join(BASE_DIR, 'static') +) + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/django/learndjango/learndjango/learndjango/urls.py b/django/learndjango/learndjango/learndjango/urls.py new file mode 100644 index 0000000..3fde76e --- /dev/null +++ b/django/learndjango/learndjango/learndjango/urls.py @@ -0,0 +1,21 @@ +""" +URL configuration for learndjango project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 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, include + +urlpatterns = [path("admin/", admin.site.urls), path("", include("myapp.urls"))] diff --git a/django/learndjango/learndjango/learndjango/wsgi.py b/django/learndjango/learndjango/learndjango/wsgi.py new file mode 100644 index 0000000..dbfc286 --- /dev/null +++ b/django/learndjango/learndjango/learndjango/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for learndjango project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'learndjango.settings') + +application = get_wsgi_application() diff --git a/django/learndjango/learndjango/manage.py b/django/learndjango/learndjango/manage.py new file mode 100755 index 0000000..2551cc5 --- /dev/null +++ b/django/learndjango/learndjango/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'learndjango.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/django/learndjango/learndjango/myapp/__init__.py b/django/learndjango/learndjango/myapp/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/django/learndjango/learndjango/myapp/__init__.py diff --git a/django/learndjango/learndjango/myapp/__pycache__/__init__.cpython-313.pyc b/django/learndjango/learndjango/myapp/__pycache__/__init__.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..a70445f --- /dev/null +++ b/django/learndjango/learndjango/myapp/__pycache__/__init__.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/__pycache__/admin.cpython-313.pyc b/django/learndjango/learndjango/myapp/__pycache__/admin.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..2293f51 --- /dev/null +++ b/django/learndjango/learndjango/myapp/__pycache__/admin.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/__pycache__/apps.cpython-313.pyc b/django/learndjango/learndjango/myapp/__pycache__/apps.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..910d8d5 --- /dev/null +++ b/django/learndjango/learndjango/myapp/__pycache__/apps.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/__pycache__/models.cpython-313.pyc b/django/learndjango/learndjango/myapp/__pycache__/models.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..1416d82 --- /dev/null +++ b/django/learndjango/learndjango/myapp/__pycache__/models.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/__pycache__/urls.cpython-313.pyc b/django/learndjango/learndjango/myapp/__pycache__/urls.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..ba543d1 --- /dev/null +++ b/django/learndjango/learndjango/myapp/__pycache__/urls.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/__pycache__/views.cpython-313.pyc b/django/learndjango/learndjango/myapp/__pycache__/views.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..2052ac9 --- /dev/null +++ b/django/learndjango/learndjango/myapp/__pycache__/views.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/admin.py b/django/learndjango/learndjango/myapp/admin.py new file mode 100644 index 0000000..7e6168b --- /dev/null +++ b/django/learndjango/learndjango/myapp/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Tour + +# Register your models here. + +admin.site.register(Tour) diff --git a/django/learndjango/learndjango/myapp/apps.py b/django/learndjango/learndjango/myapp/apps.py new file mode 100644 index 0000000..c34fb20 --- /dev/null +++ b/django/learndjango/learndjango/myapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MyappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'myapp' diff --git a/django/learndjango/learndjango/myapp/migrations/0001_initial.py b/django/learndjango/learndjango/myapp/migrations/0001_initial.py new file mode 100644 index 0000000..7d23e92 --- /dev/null +++ b/django/learndjango/learndjango/myapp/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# Generated by Django 5.2.7 on 2025-10-08 15:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Tour', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('origin_country', models.CharField(max_length=64)), + ('destination_country', models.CharField(max_length=64)), + ('number_of_nights', models.IntegerField()), + ('price', models.IntegerField()), + ], + ), + ] diff --git a/django/learndjango/learndjango/myapp/migrations/__init__.py b/django/learndjango/learndjango/myapp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/django/learndjango/learndjango/myapp/migrations/__init__.py diff --git a/django/learndjango/learndjango/myapp/migrations/__pycache__/0001_initial.cpython-313.pyc b/django/learndjango/learndjango/myapp/migrations/__pycache__/0001_initial.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..e78eb7e --- /dev/null +++ b/django/learndjango/learndjango/myapp/migrations/__pycache__/0001_initial.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/migrations/__pycache__/__init__.cpython-313.pyc b/django/learndjango/learndjango/myapp/migrations/__pycache__/__init__.cpython-313.pyc Binary files differnew file mode 100644 index 0000000..01fed90 --- /dev/null +++ b/django/learndjango/learndjango/myapp/migrations/__pycache__/__init__.cpython-313.pyc diff --git a/django/learndjango/learndjango/myapp/models.py b/django/learndjango/learndjango/myapp/models.py new file mode 100644 index 0000000..3a98c21 --- /dev/null +++ b/django/learndjango/learndjango/myapp/models.py @@ -0,0 +1,14 @@ +from django.db import models + +# Create your models here. + + +class Tour(models.Model): + origin_country = models.CharField(max_length=64) + destination_country = models.CharField(max_length=64) + number_of_nights = models.IntegerField() + price = models.IntegerField() + + # This is a string representation of the tours + def __str__(self): + return f"ID:{self.id}\nFrom:{self.origin_country}\nTo:{self.destination_country}\nNights:{self.number_of_nights}\nPrice:{self.price}" diff --git a/django/learndjango/learndjango/myapp/templates/tours/index.html b/django/learndjango/learndjango/myapp/templates/tours/index.html new file mode 100644 index 0000000..b5961d0 --- /dev/null +++ b/django/learndjango/learndjango/myapp/templates/tours/index.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Tours</title> +</head> +<body> + <h1>Tour Schedule</h1> + <ul> + {% for tour in tours %} + <li>{{tour}}</li> + {% endfor %} + </ul> +</body> +</html> diff --git a/django/learndjango/learndjango/myapp/tests.py b/django/learndjango/learndjango/myapp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django/learndjango/learndjango/myapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django/learndjango/learndjango/myapp/urls.py b/django/learndjango/learndjango/myapp/urls.py new file mode 100644 index 0000000..5f8c21b --- /dev/null +++ b/django/learndjango/learndjango/myapp/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +# Define a list of URL patterns + +urlpatterns = [path('', views.index)] diff --git a/django/learndjango/learndjango/myapp/views.py b/django/learndjango/learndjango/myapp/views.py new file mode 100644 index 0000000..a3e3a4e --- /dev/null +++ b/django/learndjango/learndjango/myapp/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render +from .models import Tour + +# Create your views here. + + +def index(request): + tours = Tour.objects.all() + context = {"tours": tours} + return render(request, "tours/index.html", context) diff --git a/django/learndjango/requirements.txt b/django/learndjango/requirements.txt new file mode 100644 index 0000000..6bd49db --- /dev/null +++ b/django/learndjango/requirements.txt @@ -0,0 +1,2 @@ +django +ipython |
