database design in google app engine

2019-07-04 23:44发布

i am designing a simple project based to do list. the idea is to define tasks under project ( no workflow - just "task is completed" or not is required. ) in a hirarchial way. i.e. each task has multiple task and that task may have other multiple task. a project can be said to be completed if all task under that project are completed. , i tought of using refrenceproeperty to create hirarchy , but could not figure out easy way ( which do not take more than 30 seconds to find all the children of a project and check weather it is completed or not ) . to detect if project is complete or not. how to design database for such job ? and also , if i need to copy the project in order to define another project , how to copy hierarchical data ?

2条回答
Melony?
2楼-- · 2019-07-05 00:28

It's probably best to implement the hierarchy of tasks by setting the parent of a task entity to the task entity or project entity to which it belongs.

I think that the trick for finding whether or not all the children of a project are complete or not would be to use ANCESTOR queries.

If you are creating your task records such that their parent is set to the task or project to which they belong, you should be able to write something like this:

all_done = db.Query().ancestor(project_entity).filter('complete = ', False).count()
if all_done > 0:
    #Not all done
else:
    #All done
查看更多
Rolldiameter
3楼-- · 2019-07-05 00:41

The overriding philosophy of the App Engine datastore, as with other nosql databases, is to do your work on write, not on read. With that in mind, you could use parent relationships, as Adam suggests, and keep an 'incomplete count' on each node, which counts the number of immediate children that aren't yet complete. When you mark a node complete, decrement its parent node's count; if that causes it to be complete, move to its parent, and so forth. With a structure like this, you can instantly show if a task is complete or not.

查看更多
登录 后发表回答