Skip to main content

Extra challenges

The best way to make new skills stick is to use them on your own. Here are some features you can add to the todo app.

There’s no walkthrough and no finished branch for these. Each challenge has a few hints and links to point you in the right direction. Pick whichever one sounds fun, and don’t worry about doing them in order.

Tip

Before you start a challenge, write a Playwright test for it. Watch it fail, then make it pass.

Add new items without reloading the page

Right now, when you add a todo item, the form does a normal POST and the whole page reloads.

Make the form use HTMX instead, so only the new item gets added to the list.

Hints:

  • Swap the form’s method="post" for hx-post.
  • Have the view return just the new item, rendered with the todo_item.html partial.
  • Use hx-target to point at the list, and hx-swap="beforeend" to add the new item to the end of it.
  • Bonus: clear the form after the item is added.

Edit todo items

Once a todo item is created, there’s no way to fix a typo in it.

Let the user click on an item to edit its title and description.

Hints:

  • Look at the HTMX click to edit example.
  • You’ll need one view that returns an edit form for an item, and one that saves the changes and returns the normal item.
  • Alpine.js is another option: show and hide the form on the page, the same way we did with the description in goal 4.

Add due dates

Give each todo item an optional due date.

Hints:

  • Add a DateField to the TodoItem model, with null=True and blank=True. Then make and run a migration.
  • Add the field to the form. A date input gives you a date picker for free.
  • Bonus: use Tailwind to show overdue items in red.

Change the sort order

Right now, the list is sorted by done, then by id.

Let the user choose how to sort the list. For example: newest first, oldest first, alphabetical, or by due date.

Hints:

  • Add a <select> with the sort options. Use hx-get and hx-trigger="change" to fetch the list again whenever the choice changes.
  • Pass the choice to the view as a query parameter, and use it in order_by.

Add pagination

If you have hundreds of todo items, the page gets very long.

Show only a few items at a time, with a way to see more.

Hints:

  • Django has a built-in Paginator.
  • Look at the HTMX click to load example for a “Load more” button.
  • The add_todos management command is handy for making lots of items to test with.

Group todo items into projects

One long list isn’t very useful once you have lots to do. Let the user organise their items into projects, like “Work” or “Home”.

Hints:

  • Add a Project model, and give TodoItem a ForeignKey to it.
  • Start small: create projects in the Django admin, and pick one when you add a todo item.
  • Then show one project’s list at a time, or group the items by project on the home page.

Add sub-items

Some tasks are big enough to break into smaller steps. Let a todo item have its own list of sub-items.

Hints:

  • A todo item can point at a parent todo item with models.ForeignKey("self", null=True, blank=True, ...). See recursive relationships.
  • Keep it to one level deep. Sub-items of sub-items get complicated quickly.
  • Think about what happens when you tick off the parent. Should the sub-items get ticked off too?

Add attachments

Let the user upload a file, like a photo or a PDF, to a todo item.

Hints:

  • Add a FileField to the model, and set up MEDIA_ROOT and MEDIA_URL. The Django docs on file uploads walk you through it.
  • A form that uploads files needs enctype="multipart/form-data". If you use HTMX, set hx-encoding instead.
  • Playwright can upload files in tests with set_input_files.