Fourth part of AppEngine Forms. This time we delete added rows from database.
Basic Form Tutorial Google AppEngine
This is the last part of basic form handling in AppEngine. This time we make delete links.
- AppEngine Forms in Python
- Submit AppEngine Forms Using POST in Python
- AppEngine Edit Form in Python
- Delete Row From Datastore in AppEngine
This is the last part of basic form handling in AppEngine. This time we make delete links.
Delete Class:
This class a link and makes a refresh/redirect.Source code viewer
class MyDeleteForm(webapp.RequestHandler): def post(self): id = int(self.request.get('id')) item = db.get(db.Key.from_path('MyModel', id)) data = MyForm(data=self.request.POST, instance=item) if data.is_valid(): entity = data.save(commit=False) entity.delete() self.redirect('/')Programming Language: Python
Generate Delete Links:
This is how you can generate delete links. If you use views and django template engine. You have to use google app engines template library and pass on the array of data through template values.This is the view file. If you don't know how to use views then here is a tutorial: Using Templates.Source code viewer
#Import this library, goes in the beginning of the file as usual from google.appengine.ext.webapp import template #This is is the array of the data. Comes from datastore using GQL. db.GqlQuery("SELECT * FROM MyModel")Programming Language: Python
You can use the same way to make the edit links automatically.Source code viewer
{% for row in query %} {% endfor %}Programming Language: HTML
This is the end of this tutorial series. Now you should have a basic form where you can submit, edit and delete data.