func (this *MainController) Get() { todos := []models.Todo{} ks, err := datastore.NewQuery("Todo").Ancestor(models.DefaultTodoList(this.AppEngineCtx)).Order("Created").GetAll(this.AppEngineCtx, &todos) if err != nil { this.Data["json"] = err return } for i := 0; i < len(todos); i++ { todos[i].Id = ks[i].IntID() } this.Data["json"] = todos }
func (this *MainController) Delete() { err := datastore.RunInTransaction(this.AppEngineCtx, func(c context.Context) error { ks, err := datastore.NewQuery("Todo").KeysOnly().Ancestor(models.DefaultTodoList(c)).Filter("Done=", true).GetAll(c, nil) if err != nil { return err } return datastore.DeleteMulti(c, ks) }, nil) if err == nil { this.Data["json"] = nil } else { this.Data["json"] = err } }