func adminHandler(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { t, _ := template.ParseFiles("admin.html") t.Execute(w, nil) } if r.Method == "POST" { ctx := appengine.NewContext(r) r.ParseForm() categoryTitle := r.FormValue("newCategory") categoryParentTitle := r.FormValue("categoryParent") locationTitle := r.FormValue("newLocation") locationParentTitle := r.FormValue("locationParent") // save category key, err := m.SaveIfTitleNoneExists(ctx, m.Category{Title: categoryParentTitle}) if err != nil { w.Write([]byte(err.Error())) } c := m.Category{Title: categoryTitle} if key != nil { c = c.SetChildDSID([]int64{key.IntID()}).(m.Category) m.SaveIfTitleNoneExists(ctx, c) } // save location key, err = m.SaveIfTitleNoneExists(ctx, m.Location{Title: locationParentTitle}) if err != nil { w.Write([]byte(err.Error())) } l := m.Location{Title: locationTitle} if key != nil { l = l.SetChildDSID([]int64{key.IntID()}).(m.Location) m.SaveIfTitleNoneExists(ctx, l) } http.Redirect(w, r, "/admin", http.StatusFound) } }