Book Image

Couchbase Essentials

Book Image

Couchbase Essentials

Overview of this book

Table of Contents (15 chapters)
Couchbase Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Nested tasks


To make our simple task list app a little more interesting, we'll add the ability to nest tasks. In other words, we'll allow some tasks to be subtasks of other tasks. Doing so requires only a slight change to our model, for example adding a ParentId property:

public class Task
{
  public string Description { get; set; }
  public bool IsComplete { get; set; }
  public string ParentId { get; set; }
  public bool Type { get { return "task"; } }
}

There are numerous ways to set up a user interface to allow parent tasks to be set. In the interest of brevity, we'll assume that our create and edit actions and views have two simple additions:

#get all tasks returned by the  
#all_incomplete view in the tasks design document
tasks = client.query("tasks", "all_incomplete")

#when saving tasks, assign the parentId
task.parent_id = request.form["parentId"]

#pass the tasks to the view
#model passed only for edit
return render_template("index.html", model=task, tasks=tasks) 

<!-- parent...