title: Google App Engine Example Modified
body: <p>I took an official example of Google App Engine, that creates a Shoppinglist, and modified it so it would:</p>
  
  <p>Create two tables (contact and Phonenumber) instead of one Shoppinglist.
  This is to understand how google deals with two tables and the Foreignkey (see code below).</p>
  
  <p>It displays everything until line 47:</p>
  
  <p>data = PhoneNumber(data=self.request.POST)
  data2 = Contact(data2=self.request.POST)</p>
  
  <p>Somehow it cant deal with the second "data2" object and gives me and error:</p>
  
  <p>TypeError: <strong>init</strong>() got an unexpected keyword argument 'data2'</p>
  
  <p>Why?
  What can I do to make it work?</p>
  
  <p>Thanks for the time.</p>
  
  <pre><code>import cgi
  
  from google.appengine.api import users
  from google.appengine.ext import db
  from google.appengine.ext import webapp
  from google.appengine.ext.webapp import template
  from google.appengine.ext.webapp.util import run_wsgi_app
  
  from google.appengine.ext.db import djangoforms
  
  class Contact(db.Model):
      name = db.StringProperty()
      birth_day = db.DateProperty()
      address = db.PostalAddressProperty()
  
  class PhoneNumber(db.Model):
      contact = db.ReferenceProperty(Contact,
                                     collection_name='phone_numbers')
      phone_type = db.StringProperty(
          choices=('home', 'work', 'fax', 'mobile', 'other'))
      number = db.PhoneNumberProperty()
  
  class PhoneNumberForm(djangoforms.ModelForm):
      class Meta:
          model = PhoneNumber
  
  class ContactForm(djangoforms.ModelForm):
      class Meta:
          model = Contact
  
  class MainPage(webapp.RequestHandler):
      def get(self):
          self.response.out.write('&lt;html&gt;&lt;body&gt;'
                                  '&lt;form method="POST" '
                                  'action="/"&gt;'
                                  '&lt;table&gt;')
          # This generates our PhoneNumber, Contact list form and writes it in the response
          self.response.out.write(PhoneNumberForm())
          self.response.out.write(ContactForm())
          self.response.out.write('&lt;/table&gt;'
                                  '&lt;input type="submit"&gt;'
                                  '&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;')
      def post(self):
          #print self.request
          #print self.request.POST
          data = PhoneNumber(data=self.request.POST)
          data2 = Contact(data2=self.request.POST)
          if data.is_valid():
              # Save the data, and redirect to the view page
              entity = data.save(commit=False)
              entity.added_by = users.get_current_user()
              entity.put()
              self.redirect('/items.html')
          if data2.is_valid():
              # Save the data, and redirect to the view page
              entity = data2.save(commit=False)
              entity.added_by = users.get_current_user()
              entity.put()
              self.redirect('/items.html')
          else:
              # Reprint the form
              self.response.out.write('&lt;html&gt;&lt;body&gt;'
                                      '&lt;form method="POST" '
                                      'action="/"&gt;'
                                      '&lt;table&gt;')
              self.response.out.write(data)
              self.response.out.write(data2)
              self.response.out.write('&lt;/table&gt;'
                                      '&lt;input type="submit"&gt;'
                                      '&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;')
  
  class ItemPage(webapp.RequestHandler):
      def get(self):
          query = db.GqlQuery("SELECT * FROM PhoneNumber ORDER BY name")
          for item in query:
              self.response.out.write('&lt;a href="/edit?id=%d"&gt;Edit&lt;/a&gt; - ' %
                                      item.key().id())
              self.response.out.write("%s - Need to buy %d, cost $%0.2f each&lt;br&gt;" %
                                      (item.name, item.quantity, item.target_price))
  
  class EditPage(webapp.RequestHandler):
      def get(self):
          id = int(self.request.get('id'))
          item = Item.get(db.Key.from_path('Item', id))
          self.response.out.write('&lt;html&gt;&lt;body&gt;'
                                  '&lt;form method="POST" '
                                  'action="/edit"&gt;'
                                  '&lt;table&gt;')
          self.response.out.write(PhoneNumberForm(instance=PhoneNumber))
          self.response.out.write(ContactForm(instance=Contact))
          self.response.out.write('&lt;/table&gt;'
                                  '&lt;input type="hidden" name="_id" value="%s"&gt;'
                                  '&lt;input type="submit"&gt;'
                                  '&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;' % id)
      def post(self):
          id = int(self.request.get('_id'))
          PhoneNumber = PhoneNumber.get(db.Key.from_path('PhoneNumber', id))
          Contact = Contact.get(db.Key.from_path('Contact', id))
          data = PhoneNumberForm(data=self.request.POST)
          data2 = ContactForm(data2=self.request.POST)
          if data.is_valid():
              # Save the data, and redirect to the view page
              entity = data.save(commit=False)
              entity.added_by = users.get_current_user()
              entity.put()
              self.redirect('/items.html')
          if data2.is_valid():
              # Save the data, and redirect to the view page
              entity = data2.save(commit=False)
              entity.added_by = users.get_current_user()
              entity.put()
              self.redirect('/items.html')
          else:
              # Reprint the form
              self.response.out.write('&lt;html&gt;&lt;body&gt;'
                                      '&lt;form method="POST" '
                                      'action="/"&gt;'
                                      '&lt;table&gt;')
              self.response.out.write(data)
              self.response.out.write(data2)
              self.response.out.write('&lt;/table&gt;'
                                      '&lt;input type="submit"&gt;'
                                      '&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;')
  
  def main():
      application = webapp.WSGIApplication(
                                           [('/', MainPage),
                                            ('/edit', EditPage),
                                            ('/items.html', ItemPage),
                                            ],
                                           debug=True)
  
      run_wsgi_app(application)
  if __name__=="__main__":
      main()
  </code></pre>