Skip to content

Commit 2dacb6c

Browse files
authored
Merge pull request #246 from profcalculus/django-todo-list
Source code steps for download
2 parents 569fd13 + 324f4cc commit 2dacb6c

File tree

136 files changed

+2957
-0
lines changed

Some content is hidden

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

136 files changed

+2957
-0
lines changed

django-todo-list/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Source files supporting the "Manage Your To-Do Lists Using Python and Django" step-by-step tutorial on Real Python.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Django Todo List
2+
3+
This folder contains project code for the _Real Python_ step-by-step project for building a to-do app with Django.
4+
5+
## Setup Instructions
6+
7+
These instructions have been tested in Ubuntu Linux and macOS. They should also work in Windows, but note that you'll need to use a different command to activate your virtual environment as described in Step 3. Please consult the [`venv` documentation](https://docs.python.org/3/library/venv.html#creating-virtual-environments) for greater detail on the use of virtual environments.
8+
9+
1. Navigate into the project directory (`source_code/`).
10+
2. Create a virtual environment in a `venv/` folder by typing `python -m venv venv` in your console.
11+
3. Activate the venv using `source venv/bin/activate` (Linux, MacOS) or `venv\Scripts\activate.bat` (Windows).
12+
4. Install the dependencies with `python -m pip install -r requirements.txt`
13+
5. Generate the empty SQLite database and tables using `python manage.py migrate`
14+
5. Run the app with `python manage.py runserver`
15+
6. Browse to the [app home page](http://localhost:8000/) to see the list of todo lists, which will initially be empty.
16+
17+
You can now start using the UI to add your to-do lists and to-do items to the database. The data will be stored in a new `db.sqlite3` file in the root of your project directory.
18+
19+
You can also use Django's auto-generated [admin interface](https://realpython.com/customize-django-admin-python/#setting-up-the-django-admin) at `http://localhost:8000/admin/` to view, add, and edit the data.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_project.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
asgiref==3.4.1
2+
Django==3.2.9
3+
pytz==2021.3
4+
sqlparse==0.4.2

django-todo-list/source_code_final/todo_app/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# todo_list/todo_app/admin.py
2+
3+
from django.contrib import admin
4+
from todo_app.models import ToDoItem, ToDoList
5+
6+
admin.site.register(ToDoItem)
7+
admin.site.register(ToDoList)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class TodoAppConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "todo_app"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 3.2.9 on 2021-12-19 19:49
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import todo_app.models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='ToDoList',
18+
fields=[
19+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('title', models.CharField(max_length=100, unique=True)),
21+
],
22+
),
23+
migrations.CreateModel(
24+
name='ToDoItem',
25+
fields=[
26+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27+
('title', models.CharField(max_length=100)),
28+
('description', models.TextField(blank=True, null=True)),
29+
('created_date', models.DateTimeField(auto_now_add=True)),
30+
('due_date', models.DateTimeField(default=todo_app.models.one_week_hence)),
31+
('todo_list', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='todo_app.todolist')),
32+
],
33+
options={
34+
'ordering': ['due_date'],
35+
},
36+
),
37+
]

django-todo-list/source_code_final/todo_app/migrations/__init__.py

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# todo_list/todo_app/models.py
2+
from django.utils import timezone
3+
4+
from django.db import models
5+
from django.urls import reverse
6+
7+
8+
def one_week_hence():
9+
return timezone.now() + timezone.timedelta(days=7)
10+
11+
12+
class ToDoList(models.Model):
13+
title = models.CharField(max_length=100, unique=True)
14+
15+
def get_absolute_url(self):
16+
return reverse("list", args=[self.id])
17+
18+
def __str__(self):
19+
return self.title
20+
21+
22+
class ToDoItem(models.Model):
23+
title = models.CharField(max_length=100)
24+
description = models.TextField(null=True, blank=True)
25+
created_date = models.DateTimeField(auto_now_add=True)
26+
due_date = models.DateTimeField(default=one_week_hence)
27+
todo_list = models.ForeignKey(ToDoList, on_delete=models.CASCADE)
28+
29+
def get_absolute_url(self):
30+
return reverse(
31+
"item-update", args=[str(self.todo_list.id), str(self.id)]
32+
)
33+
34+
def __str__(self):
35+
return f"{self.title}: due {self.due_date}"
36+
37+
class Meta:
38+
ordering = ["due_date"]

0 commit comments

Comments
 (0)