diff --git a/django-migrations/README.md b/django-migrations/README.md index 9012dd1030..5a5e64940d 100644 --- a/django-migrations/README.md +++ b/django-migrations/README.md @@ -4,12 +4,21 @@ This directory contains the Django project created in the article [Django Migrat It is also used in the follow up article [Digging Deeper into Migrations](https://realpython.com/digging-deeper-into-migrations/). -**Note:** The code in this directory has been reformatted with black and might therefore differ slightly in codestyle from the code originally generated by Django. +**Note:** The code in this directory has been reformatted with Ruff and might therefore differ slightly in codestyle from the code originally generated by Django. ## Installation -This Project has been tested with Python 3.6 and Django 2.1, but you should be able to run it with an Django 2.x and a compatible Python. The recommended way to install it is using `pip` and a virtualenv: +This project has been tested with Python 3.14 and Django 6.1. The recommended way to install it is using `pip` and a virtual environment: - $ python3 -m venv .venv - $ source .venv/bin/activate - (.venv) $ pip install "Django==2.*" +```console +$ python3 -m venv .venv +$ source .venv/bin/activate +(.venv) $ python -m pip install -r requirements.txt +``` + +Then change into the `bitcoin_tracker/` directory and apply the migrations to the bundled SQLite database: + +```console +(.venv) $ cd bitcoin_tracker +(.venv) $ python manage.py migrate +``` diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py new file mode 100644 index 0000000000..7318d6bfdb --- /dev/null +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for bitcoin_tracker 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/6.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bitcoin_tracker.settings") + +application = get_asgi_application() diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py index 7b3748cdce..64e7dad27d 100644 --- a/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py @@ -1,23 +1,23 @@ """ Django settings for bitcoin_tracker project. -Generated by 'django-admin startproject' using Django 2.1.5. +Generated by 'django-admin startproject' using Django 6.1. For more information on this file, see -https://docs.djangoproject.com/en/2.1/topics/settings/ +https://docs.djangoproject.com/en/6.1/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.1/ref/settings/ +https://docs.djangoproject.com/en/6.1/ref/settings/ """ -import os +from pathlib import Path -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# 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/2.1/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/6.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "dyf)n0fejvk73!&k5_uq4ce7=e6-0+7sy)rm$w=@rg_!xk!5n3" @@ -59,48 +59,49 @@ "APP_DIRS": True, "OPTIONS": { "context_processors": [ - "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", - ] + ], }, - } + }, ] WSGI_APPLICATION = "bitcoin_tracker.wsgi.application" # Database -# https://docs.djangoproject.com/en/2.1/ref/settings/#databases +# https://docs.djangoproject.com/en/6.1/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + "NAME": BASE_DIR / "db.sqlite3", } } # Password validation -# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/6.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, - {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator" + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator" + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] # Internationalization -# https://docs.djangoproject.com/en/2.1/topics/i18n/ +# https://docs.djangoproject.com/en/6.1/topics/i18n/ LANGUAGE_CODE = "en-us" @@ -108,12 +109,20 @@ USE_I18N = True -USE_L10N = True - USE_TZ = True # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.1/howto/static-files/ +# https://docs.djangoproject.com/en/6.1/howto/static-files/ + +STATIC_URL = "static/" -STATIC_URL = "/static/" + +# Email +# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration + +MAILERS = { + "default": { + "BACKEND": "django.core.mail.backends.console.EmailBackend", + }, +} diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py index 1903c817b4..7a18e7c693 100644 --- a/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py @@ -1,7 +1,8 @@ -"""bitcoin_tracker URL Configuration +""" +URL configuration for bitcoin_tracker project. The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.1/topics/http/urls/ + https://docs.djangoproject.com/en/6.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views @@ -17,4 +18,6 @@ from django.contrib import admin from django.urls import path -urlpatterns = [path("admin/", admin.site.urls)] +urlpatterns = [ + path("admin/", admin.site.urls), +] diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py index b44ed99a81..2f83792630 100644 --- a/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py @@ -4,7 +4,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/6.1/howto/deployment/wsgi/ """ import os diff --git a/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py b/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py index 1b53a6925d..b9157caae1 100644 --- a/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py +++ b/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py @@ -1,10 +1,9 @@ -# Generated by Django 2.1.5 on 2019-02-05 20:23 +# Generated by Django 6.1 on 2026-09-16 14:49 from django.db import migrations, models class Migration(migrations.Migration): - initial = True dependencies = [] @@ -15,7 +14,7 @@ class Migration(migrations.Migration): fields=[ ( "id", - models.AutoField( + models.BigAutoField( auto_created=True, primary_key=True, serialize=False, @@ -26,5 +25,5 @@ class Migration(migrations.Migration): ("price", models.DecimalField(decimal_places=2, max_digits=7)), ("volume", models.PositiveIntegerField()), ], - ) + ), ] diff --git a/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py b/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py index 365924d104..b2f781fe57 100644 --- a/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py +++ b/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py @@ -1,16 +1,17 @@ -# Generated by Django 2.1.5 on 2019-02-05 20:26 +# Generated by Django 6.1 on 2026-09-16 14:49 from django.db import migrations, models class Migration(migrations.Migration): - - dependencies = [("historical_data", "0001_initial")] + dependencies = [ + ("historical_data", "0001_initial"), + ] operations = [ migrations.AlterField( model_name="pricehistory", name="volume", field=models.DecimalField(decimal_places=3, max_digits=7), - ) + ), ] diff --git a/django-migrations/bitcoin_tracker/manage.py b/django-migrations/bitcoin_tracker/manage.py index df9510487c..50dfac7be1 100755 --- a/django-migrations/bitcoin_tracker/manage.py +++ b/django-migrations/bitcoin_tracker/manage.py @@ -1,8 +1,12 @@ #!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" + import os import sys -if __name__ == "__main__": + +def main(): + """Run administrative tasks.""" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bitcoin_tracker.settings") try: from django.core.management import execute_from_command_line @@ -13,3 +17,7 @@ "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/django-migrations/requirements.txt b/django-migrations/requirements.txt new file mode 100644 index 0000000000..4a19989ab2 --- /dev/null +++ b/django-migrations/requirements.txt @@ -0,0 +1,3 @@ +asgiref==3.12.1 +Django==6.1 +sqlparse==0.6.0