Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Couchbase Essentials

You're reading from  Couchbase Essentials

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781784394493
Pages 170 pages
Edition 1st Edition
Languages

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}