Manage Your To-Do Lists Using Python and Django


Have you ever struggled to keep track of the things that you need to do? Perhaps you’re in the habit of using a handwritten to-do list to remind you of what needs doing, and by when. But handwritten notes have a way of getting lost or forgotten.
Because you’re a Python coder, it makes sense to build a Django to-do list manager!

In this step-by-step tutorial, you’re going to create a web app using Django. You’ll learn how Django can integrate with a database that stores all your to-do items in lists that you can define. Each item will have a title, a description, and a deadline. With this app, you can manage your own deadlines and help your entire team stay on track!

In this tutorial, you’ll learn how to:

Create a web app using Django
Build a data model with one-to-many relationships
Use the Django admin interface to explore your data model and add test data
Design templates for displaying your lists
Leverage class-based views to handle the standard database operations
Control the Django URL dispatcher by creating URL configurations

Along the way, you’ll learn how Django’s class-based views leverage the power of object-oriented programming. That’ll save you a ton of development effort!

Get Source Code: Click here to get the source code you’ll use to build your to-do list app.


In this tutorial, you’ll build a Django to-do list manager. Your main page will display all of your to-do lists. By clicking the Add a new list button, you’ll display a page where you can name and create a new list:

You’ll be able to add to-do items to your list by clicking Add a new item. There, you can give your item a title, and you can add more details in the Description box. You can even set a due date.

Project Overview

To build this app, you’ll start by creating a virtual environment and setting up a Django project.
Next, you’ll design a data model that represents the relationships between to-do items and lists.
You’ll use Django’s built-in object-relational mapping tool to automatically generate the database and tables that’ll support this model.

As you develop your Django to-do list app, you’ll use Django’s handy runserver command whenever you need to verify that things are working as expected. This can help even before your web pages are ready, thanks to Django’s ready-made admin interface.

Next, you’ll develop your own web pages to display your app. In Django, these take the form of templates. Templates are skeleton HTML pages that can be populated with real application data.

Templates aren’t meant to provide much logic, such as deciding which template to display and what data to send it. To perform that logic, you’ll need views. Django’s views are the natural home for the application’s logic.

You’ll code views and templates for list creation and updates, as well as for the items that those lists will contain.
You’ll learn how to use Django’s URL dispatcher to connect your pages and pass them the data that they need.
Next, you’ll add more views and templates that enable your users to delete lists and items.

Finally, you’ll test your new user interface by adding, editing, and deleting to-do lists and to-do items.

By completing this project, you’ll learn how to build this app and also understand how the various components fit together. Then, you’ll be ready to undertake your next Django project on your own.


To complete this tutorial, you should be comfortable with the following skills:

Running Python scripts from the command line
Coding in Python IDLE, or your favorite code editor
Using Python modules and packages
Understanding object-oriented programming in Python, including object inheritance

If you don’t have all of the prerequisite knowledge before starting this tutorial, that’s okay. In fact, you might learn more by going ahead and getting started! You can always stop and review the resources linked here if you get stuck.

You don’t need to have used Django before, because you’ll get step-by-step instructions for installing and using it below. However, if you’re interested in a more detailed introduction to this powerful web framework, there’s a whole range of Django tutorials that you can consult.

Step 1: Set Up Your Virtual Environment and Django

In this step, you’re going to perform a few standard housekeeping tasks that you should only need to do once per Django project. Specifically, you’ll make and activate a virtual environment, install Django, and test that Django is installed correctly.

Read the full article at »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]