To-Do List (Python). Stage 4/4

Bye-bye, completed tasks

Report a typo

Description

Planning is one thing, but when we need to knuckle down and put our plans into action, we tend to push our tasks back until the very last minute. Or even worse, we often tend to miss the established deadline. It happens even to the best of us! In this stage, let's implement the ability to see the tasks with a missed deadline and delete them.

To delete a row from the table, use the delete() method that accepts an object. As you remember, each row is represented by a Python object:

from datetime import datetime

# delete all rows where the date column is today's date
session.query(Table).filter(Table.date == datetime.today().date()).delete()

# delete a specific row
rows = session.query(Table).filter(Table.date < datetime.today().date()).all()
specific_row = rows[0] # in case rows is not empty
session.delete(specific_row)

# don't forget to commit the changes
session.commit()

Objectives

Add the following items to your menu:

  1. Missed tasks. It prints all the tasks with a missed deadline. Order the tasks by the deadline date;
  2. Delete a task. It deletes the chosen task. Print Nothing to delete if the tasks list is empty. This menu should also print all the tasks sorted by the deadline date and ask to enter the number for the task.

See the Example section for further detail.

Example

The greater-than symbol followed by a space (> ) represents the user input. Note that it's not part of the input.

Example 1: possible output of the program

1) Today's tasks
2) Week's tasks
3) All tasks
4) Missed tasks
5) Add a task 
6) Delete a task 
0) Exit
> 4

Missed tasks:
1. Learn the for-loop. 19 Apr

1) Today's tasks
2) Week's tasks
3) All tasks
4) Missed tasks
5) Add a task 
6) Delete a task 
0) Exit
> 6

Choose the number of the task you want to delete:
1. Learn the for-loop. 19 Apr
2. Learn the basics of SQL. 29 Apr
> 1
The task has been deleted!

1) Today's tasks
2) Week's tasks
3) All tasks
4) Missed tasks
5) Add a task 
6) Delete a task 
0) Exit
> 4

Missed tasks:
All tasks have been completed! 

1) Today's tasks
2) Week's tasks
3) All tasks
4) Missed tasks
5) Add a task
6) Delete a task
0) Exit
> 0

Bye!
Write a program
IDE integration
Checking the IDE status
___

Create a free account to access the full topic

Topics in stage