Skip to content

Commit 1b0275c

Browse files
authored
Django diary update (#625)
* Django version update Mostly documentation links and minor changes * Run isort * Move requirements into root folder * Add new readme * Add formatted migrations * Add CSS file * Add templates * Removed test files * Add placeholder content for empty file * Remove docstring from urls.py files
1 parent 21c0a2e commit 1b0275c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+378
-403
lines changed

django-diary/README.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
# Django Diary
2-
3-
> **Note:** The project is built with `Python 3.9.1`, but should work with any Python3 version.
4-
5-
## About this repository
1+
# Build Your Personal Diary With Django
62

73
This is a companion project to the ["Build Your Personal Diary With Django"](https://realpython.com/django-diary-project-python/) tutorial on Real Python.
84
Visit the article to follow along or download the content of `source_code_final` folder from this repository.
95

10-
## How To Run `django-diary`
116

127
Type the following commands into a terminal to create and activate a virtual environment and install the requirements:
138

@@ -16,8 +11,7 @@ $ python -m venv venv
1611
$ source venv/bin/activate
1712
$ python -m pip install -r requirements.txt
1813
```
19-
20-
Then run the database migrations and create a superuser:
14+
Then you can navigate into a step folder, run the database migrations, and create a superuser:
2115

2216
```sh
2317
$ python manage.py migrate
@@ -30,6 +24,3 @@ Finally, run the local Django development server:
3024
$ python manage.py runserver
3125
```
3226

33-
## License
34-
35-
Distributed under the MIT license.

django-diary/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
asgiref==3.8.1
2+
Django==5.1.4
3+
sqlparse==0.5.3

django-diary/source_code_final/diary/asgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
It exposes the ASGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
88
"""
99

1010
import os

django-diary/source_code_final/diary/settings.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
Django settings for diary project.
33
4-
Generated by 'django-admin startproject' using Django 3.2.1.
4+
Generated by 'django-admin startproject' using Django 5.1.4.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/topics/settings/
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
88
99
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/3.2/ref/settings/
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
1111
"""
1212

1313
from pathlib import Path
@@ -17,11 +17,11 @@
1717

1818

1919
# Quick-start development settings - unsuitable for production
20-
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
20+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
2323
SECRET_KEY = (
24-
"django-insecure-kom*7k3n4v3gj_mrcp19r_(rl#v^t2v90i_t2dd9&4*4e1nb%+"
24+
"django-insecure-lxfw6(cjvk39um)u-pot#ri79*14rg_c#1nharb)&l10%5jymv"
2525
)
2626

2727
# SECURITY WARNING: don't run with debug turned on in production!
@@ -74,7 +74,7 @@
7474

7575

7676
# Database
77-
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
77+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
7878

7979
DATABASES = {
8080
"default": {
@@ -85,7 +85,7 @@
8585

8686

8787
# Password validation
88-
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
88+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
8989

9090
AUTH_PASSWORD_VALIDATORS = [
9191
{
@@ -104,25 +104,23 @@
104104

105105

106106
# Internationalization
107-
# https://docs.djangoproject.com/en/3.2/topics/i18n/
107+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
108108

109109
LANGUAGE_CODE = "en-us"
110110

111111
TIME_ZONE = "UTC"
112112

113113
USE_I18N = True
114114

115-
USE_L10N = True
116-
117115
USE_TZ = True
118116

119117

120118
# Static files (CSS, JavaScript, Images)
121-
# https://docs.djangoproject.com/en/3.2/howto/static-files/
119+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
122120

123-
STATIC_URL = "/static/"
121+
STATIC_URL = "static/"
124122

125123
# Default primary key field type
126-
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
124+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
127125

128126
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

django-diary/source_code_final/diary/wsgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
It exposes the WSGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
88
"""
99

1010
import os
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1-
# Generated by Django 3.2.1 on 2021-05-09 17:12
1+
# Generated by Django 5.1.4 on 2025-01-06 17:01
22

3-
from django.db import migrations, models
43
import django.utils.timezone
4+
from django.db import migrations, models
55

66

77
class Migration(migrations.Migration):
8-
98
initial = True
109

11-
dependencies = [
12-
]
10+
dependencies = []
1311

1412
operations = [
1513
migrations.CreateModel(
16-
name='Entry',
14+
name="Entry",
1715
fields=[
18-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19-
('title', models.CharField(max_length=200)),
20-
('content', models.TextField()),
21-
('date_created', models.DateTimeField(default=django.utils.timezone.now)),
16+
(
17+
"id",
18+
models.BigAutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("title", models.CharField(max_length=200)),
26+
("content", models.TextField()),
27+
(
28+
"date_created",
29+
models.DateTimeField(default=django.utils.timezone.now),
30+
),
2231
],
32+
options={
33+
"verbose_name_plural": "Entries",
34+
},
2335
),
2436
]

django-diary/source_code_final/entries/static/css/diary.css

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ h2, h3 {
3131
}
3232

3333
h2 {
34-
/* background-color: lightpink; */
3534
background-color: aquamarine;
3635
}
3736

Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
{% load static %}
22
<!DOCTYPE html>
33
<html lang="en">
4-
5-
<head>
6-
<meta charset="UTF-8">
7-
<title>My Diary</title>
8-
<link rel="stylesheet" href="{% static 'css/diary.css' %}">
9-
</head>
10-
11-
<body>
12-
<h1><a href="/">Dear diary …</a></h1>
13-
14-
{% if messages %}
15-
<ul class="messages">
16-
{% for message in messages %}
17-
<li class="message">
18-
{{ message }}
19-
</li>
20-
{% endfor %}
21-
</ul>
22-
{% endif %}
23-
24-
{% block content %}{% endblock %}
25-
26-
<hr>
27-
<a href="{% url 'admin:logout' %}">Logout</a>
28-
</body>
29-
30-
</html>
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>My Diary</title>
7+
<link rel="stylesheet" href="{% static 'css/diary.css' %}">
8+
</head>
9+
<body>
10+
<h1>
11+
<a href="/">Dear diary …</a>
12+
</h1>
13+
{% if messages %}
14+
<ul class="messages">
15+
{% for message in messages %}<li class="message">{{ message }}</li>{% endfor %}
16+
</ul>
17+
{% endif %}
18+
{% block content %}
19+
{% endblock content %}
20+
<hr>
21+
<form method="post" action="{% url 'admin:logout' %}">
22+
{% csrf_token %}
23+
<input type="submit" value="Logout" />
24+
</form>
25+
</body>
26+
</html>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{% extends "entries/base.html" %}
22
{% block content %}
3-
<form method="post">{% csrf_token %}
3+
<form method="post">
4+
{% csrf_token %}
45
<p>
5-
Are you sure you want to delete <em>"{{ entry.title }}"</em><br>
6+
Are you sure you want to delete
7+
<em>"{{ entry.title }}"</em>
68
created on {{ entry.date_created|date:'Y-m-d' }}?
79
</p>
810
<input type="submit" value="Confirm">
911
</form>
1012
<a href="{% url 'entry-detail' entry.id %}">
1113
<button>Cancel</button>
1214
</a>
13-
{% endblock %}
15+
{% endblock content %}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{% extends "entries/base.html" %}
2-
32
{% block content %}
43
<article>
54
<h2>{{ entry.date_created|date:'Y-m-d H:i' }}</h2>
65
<h3>{{ entry.title }}</h3>
76
<p>{{ entry.content }}</p>
87
</article>
9-
10-
<p>
11-
<a href="{% url 'entry-update' entry.id %}">✍️ Edit</a>
12-
<a href="{% url 'entry-delete' entry.id %}">⛔ Delete</a>
13-
</p>
14-
{% endblock %}
8+
<p>
9+
<a href="{% url 'entry-update' entry.id %}">✍️ Edit</a>
10+
<a href="{% url 'entry-delete' entry.id %}">⛔ Delete</a>
11+
</p>
12+
{% endblock content %}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{% extends "entries/base.html" %}
22
{% block content %}
3-
<form method="post">{% csrf_token %}
3+
<form method="post">
4+
{% csrf_token %}
45
{{ form.as_p }}
56
<input type="submit" value="Save">
67
</form>
78
{% if entry %}
89
<a href="{% url 'entry-detail' entry.id %}">
9-
<button>Cancel</button>
10+
<button>Cancel</button>
1011
</a>
1112
{% else %}
1213
<a href="{% url 'entry-list' %}">
13-
<button>Cancel</button>
14+
<button>Cancel</button>
1415
</a>
1516
{% endif %}
16-
{% endblock %}
17+
{% endblock content %}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
{% extends "entries/base.html" %}
2-
32
{% block content %}
43
<article>
5-
<h2 class="mark">{% now "Y-m-d H:i" %}</em></h2>
6-
<a href="{% url 'entry-create' %}"><button>Add new entry</button></a>
4+
<h2 class="mark">
5+
{% now "Y-m-d H:i" %}</em>
6+
</h2>
7+
<a href="{% url 'entry-create' %}">
8+
<button>Add new entry</button>
9+
</a>
10+
</article>
11+
{% for entry in entry_list %}
12+
<article>
13+
<h2 class="{{ entry.date_created|date:'l' }}">{{ entry.date_created|date:'Y-m-d H:i' }}</h2>
14+
<h3>
15+
<a href="{% url 'entry-detail' entry.id %}">{{ entry.title }}</a>
16+
</h3>
717
</article>
8-
{% for entry in entry_list %}
9-
<article>
10-
<h2 class="{{ entry.date_created|date:'l' }}">
11-
{{ entry.date_created|date:'Y-m-d H:i' }}
12-
</h2>
13-
<h3>
14-
<a href="{% url 'entry-detail' entry.id %}">
15-
{{ entry.title }}
16-
</a>
17-
</h3>
18-
</article>
19-
{% endfor %}
20-
{% endblock %}
18+
{% endfor %}
19+
{% endblock content %}

django-diary/source_code_final/requirements.txt

-1
This file was deleted.

django-diary/source_code_step_1/diary/asgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
It exposes the ASGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
88
"""
99

1010
import os

0 commit comments

Comments
 (0)