Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 14 additions & 5 deletions django-migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
16 changes: 16 additions & 0 deletions django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py
Original file line number Diff line number Diff line change
@@ -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()
53 changes: 31 additions & 22 deletions django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -59,61 +59,70 @@
"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"

TIME_ZONE = "UTC"

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",
},
}
9 changes: 6 additions & 3 deletions django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
]
2 changes: 1 addition & 1 deletion django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -15,7 +14,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
Expand All @@ -26,5 +25,5 @@ class Migration(migrations.Migration):
("price", models.DecimalField(decimal_places=2, max_digits=7)),
("volume", models.PositiveIntegerField()),
],
)
),
]
Original file line number Diff line number Diff line change
@@ -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),
)
),
]
10 changes: 9 additions & 1 deletion django-migrations/bitcoin_tracker/manage.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,3 +17,7 @@
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions django-migrations/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
asgiref==3.12.1
Django==6.1
sqlparse==0.6.0
Loading