def delete(self, id=None): #if there is an id, delete it if id: #Remove exercise from workouts for w in Workout.query().fetch( ): #fetch all workout from the database delFlag = -1 for i, exID in enumerate(w.exerciseIDs): if exID == id: delFlag = i self.response.write("match found" + str(i)) if delFlag != -1: w.exerciseIDs.pop(delFlag) w.put() ndb.Key(urlsafe=id).delete() #delete workout
def get(self, id=None): #return workout ids with list of exercise ids in JSON format relationship_dict = [] #dictionary to store relationships in if id: for r in Workout.query().fetch( ): #fetch all workout from the database r_d = "{\"workoutURLID\":\"" + r.workoutURLID + "\"" y = 0 for x in r.exerciseIDs: r_d = r_d + ", \"exerciseURLID" + str( y) + "\":\"" + r.exerciseIDs[y] + "\"" y = y + 1 #self.response.write(r_d) r_d = r_d + "}" relationship_dict.append(r_d) self.response.write(json.dumps( relationship_dict)) ###u' is being generated here by json.dumps()