Skip to content

Commit

Permalink
Django diary update (#625)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
acsany authored Jan 9, 2025
1 parent 21c0a2e commit 1b0275c
Show file tree
Hide file tree
Showing 65 changed files with 378 additions and 403 deletions.
13 changes: 2 additions & 11 deletions django-diary/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Django Diary

> **Note:** The project is built with `Python 3.9.1`, but should work with any Python3 version.
## About this repository
# Build Your Personal Diary With Django

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

## How To Run `django-diary`

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

Expand All @@ -16,8 +11,7 @@ $ python -m venv venv
$ source venv/bin/activate
$ python -m pip install -r requirements.txt
```

Then run the database migrations and create a superuser:
Then you can navigate into a step folder, run the database migrations, and create a superuser:

```sh
$ python manage.py migrate
Expand All @@ -30,6 +24,3 @@ Finally, run the local Django development server:
$ python manage.py runserver
```

## License

Distributed under the MIT license.
3 changes: 3 additions & 0 deletions django-diary/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
asgiref==3.8.1
Django==5.1.4
sqlparse==0.5.3
2 changes: 1 addition & 1 deletion django-diary/source_code_final/diary/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os
Expand Down
24 changes: 11 additions & 13 deletions django-diary/source_code_final/diary/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
Django settings for diary project.
Generated by 'django-admin startproject' using Django 3.2.1.
Generated by 'django-admin startproject' using Django 5.1.4.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
Expand All @@ -17,11 +17,11 @@


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

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

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


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
"default": {
Expand All @@ -85,7 +85,7 @@


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

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -104,25 +104,23 @@


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
# https://docs.djangoproject.com/en/5.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/3.2/howto/static-files/
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = "/static/"
STATIC_URL = "static/"

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

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
2 changes: 1 addition & 1 deletion django-diary/source_code_final/diary/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/3.2/howto/deployment/wsgi/
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""

import os
Expand Down
32 changes: 22 additions & 10 deletions django-diary/source_code_final/entries/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
# Generated by Django 3.2.1 on 2021-05-09 17:12
# Generated by Django 5.1.4 on 2025-01-06 17:01

from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Entry',
name="Entry",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('content', models.TextField()),
('date_created', models.DateTimeField(default=django.utils.timezone.now)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=200)),
("content", models.TextField()),
(
"date_created",
models.DateTimeField(default=django.utils.timezone.now),
),
],
options={
"verbose_name_plural": "Entries",
},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ h2, h3 {
}

h2 {
/* background-color: lightpink; */
background-color: aquamarine;
}

Expand Down
50 changes: 23 additions & 27 deletions django-diary/source_code_final/entries/templates/entries/base.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>My Diary</title>
<link rel="stylesheet" href="{% static 'css/diary.css' %}">
</head>

<body>
<h1><a href="/">Dear diary …</a></h1>

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li class="message">
{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}

{% block content %}{% endblock %}

<hr>
<a href="{% url 'admin:logout' %}">Logout</a>
</body>

</html>
<head>
<meta charset="UTF-8">
<title>My Diary</title>
<link rel="stylesheet" href="{% static 'css/diary.css' %}">
</head>
<body>
<h1>
<a href="/">Dear diary …</a>
</h1>
{% if messages %}
<ul class="messages">
{% for message in messages %}<li class="message">{{ message }}</li>{% endfor %}
</ul>
{% endif %}
{% block content %}
{% endblock content %}
<hr>
<form method="post" action="{% url 'admin:logout' %}">
{% csrf_token %}
<input type="submit" value="Logout" />
</form>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{% extends "entries/base.html" %}
{% block content %}
<form method="post">{% csrf_token %}
<form method="post">
{% csrf_token %}
<p>
Are you sure you want to delete <em>"{{ entry.title }}"</em><br>
Are you sure you want to delete
<em>"{{ entry.title }}"</em>
created on {{ entry.date_created|date:'Y-m-d' }}?
</p>
<input type="submit" value="Confirm">
</form>
<a href="{% url 'entry-detail' entry.id %}">
<button>Cancel</button>
</a>
{% endblock %}
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{% extends "entries/base.html" %}

{% block content %}
<article>
<h2>{{ entry.date_created|date:'Y-m-d H:i' }}</h2>
<h3>{{ entry.title }}</h3>
<p>{{ entry.content }}</p>
</article>

<p>
<a href="{% url 'entry-update' entry.id %}">✍️ Edit</a>
<a href="{% url 'entry-delete' entry.id %}">⛔ Delete</a>
</p>
{% endblock %}
<p>
<a href="{% url 'entry-update' entry.id %}">✍️ Edit</a>
<a href="{% url 'entry-delete' entry.id %}">⛔ Delete</a>
</p>
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{% extends "entries/base.html" %}
{% block content %}
<form method="post">{% csrf_token %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
{% if entry %}
<a href="{% url 'entry-detail' entry.id %}">
<button>Cancel</button>
<button>Cancel</button>
</a>
{% else %}
<a href="{% url 'entry-list' %}">
<button>Cancel</button>
<button>Cancel</button>
</a>
{% endif %}
{% endblock %}
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{% extends "entries/base.html" %}

{% block content %}
<article>
<h2 class="mark">{% now "Y-m-d H:i" %}</em></h2>
<a href="{% url 'entry-create' %}"><button>Add new entry</button></a>
<h2 class="mark">
{% now "Y-m-d H:i" %}</em>
</h2>
<a href="{% url 'entry-create' %}">
<button>Add new entry</button>
</a>
</article>
{% for entry in entry_list %}
<article>
<h2 class="{{ entry.date_created|date:'l' }}">{{ entry.date_created|date:'Y-m-d H:i' }}</h2>
<h3>
<a href="{% url 'entry-detail' entry.id %}">{{ entry.title }}</a>
</h3>
</article>
{% for entry in entry_list %}
<article>
<h2 class="{{ entry.date_created|date:'l' }}">
{{ entry.date_created|date:'Y-m-d H:i' }}
</h2>
<h3>
<a href="{% url 'entry-detail' entry.id %}">
{{ entry.title }}
</a>
</h3>
</article>
{% endfor %}
{% endblock %}
{% endfor %}
{% endblock content %}
1 change: 0 additions & 1 deletion django-diary/source_code_final/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion django-diary/source_code_step_1/diary/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os
Expand Down
Loading

0 comments on commit 1b0275c

Please sign in to comment.